Skip to content

Commit 7448800

Browse files
feat: add gradle build script to pubsub/spring tutorial (GoogleCloudPlatform#6585)
* feat: add gradle build script * remove extra white lines * typo * rename bootRun property
1 parent f1c8f46 commit 7448800

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

pubsub/spring/README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ When the application starts, it will do the following every ten seconds:
1616

1717
This sample requires [Java](https://www.java.com/en/download/) and [Maven](http://maven.apache.org/) for building the application.
1818

19-
1. **Follow the Java development environment set-up instructions in [the documentation](https://cloud.google.com/java/docs/setup).**
19+
1. **Follow the Java development environment set-up instructions in [the documentation](https://cloud.google.com/java/docs/setup).**
2020

21-
1. Enable APIs for your project.
21+
2. Enable APIs for your project.
2222
[Click here](https://console.cloud.google.com/flows/enableapi?apiid=pubsub.googleapis.com&showconfirmation=true)
2323
to visit Cloud Platform Console and enable the Google Cloud Pub/Sub API.
2424

25-
1. Create a new topic `topic-one` and attach a subscription `sub-one` to it, then do the same for `topic-two` and `sub-two`, via the Cloud Platform Console's
25+
3. Create a new topic `topic-one` and attach a subscription `sub-one` to it, then do the same for `topic-two` and `sub-two`, via the Cloud Platform Console's
2626
[Cloud Pub/Sub section](http://console.cloud.google.com/pubsub).
2727

28-
1. Enable application default credentials by running the command `gcloud auth application-default login`.
28+
4. Enable application default credentials by running the command `gcloud auth application-default login`.
29+
30+
5. Run the following Maven or Gradle commands to run `PubSubApplication`:
2931

30-
1. Run the following Maven command to run `PubSubApplication`:
3132
```
3233
mvn clean spring-boot:run
3334
```
35+
36+
```
37+
gradle bootRun
38+
```
39+
3440
You should observe an incoming message getting sent to `topic-one`, received from `sub-one`, sent to `topic-two`, and received from `topic-two` in the logged messages:
3541
```
3642
2020-08-10 17:29:18.807 INFO 27310 --- [ main] demo.PubSubApplication : Started PubSubApplication in 6.063 seconds (JVM running for 6.393)

pubsub/spring/build.gradle

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id 'application'
19+
id 'java'
20+
id 'org.springframework.boot' version '2.5.7'
21+
}
22+
23+
repositories {
24+
mavenCentral()
25+
}
26+
27+
bootRun {
28+
mainClassName = 'demo.PubSubApplication'
29+
}
30+
31+
group = 'demo'
32+
version = '1.0.0-SNAPSHOT'
33+
description = 'Spring Cloud GCP Pub/Sub Code Sample'
34+
java.sourceCompatibility = JavaVersion.VERSION_1_8
35+
36+
dependencies {
37+
implementation 'com.github.spotbugs:spotbugs-annotations:4.5.0'
38+
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.7'
39+
implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub:2.0.6'
40+
implementation 'org.springframework.integration:spring-integration-core:5.5.6'
41+
implementation 'com.google.cloud:spring-cloud-gcp-pubsub-stream-binder:2.0.6'
42+
testImplementation 'junit:junit:4.13.2'
43+
testImplementation 'com.google.truth:truth:1.1.3'
44+
testImplementation 'org.springframework.boot:spring-boot-test:2.5.7'
45+
}

pubsub/spring/pom.xml

+1-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>org.springframework.boot</groupId>
4949
<artifactId>spring-boot-dependencies</artifactId>
50-
<version>2.5.5</version>
50+
<version>2.5.7</version>
5151
<type>pom</type>
5252
<scope>import</scope>
5353
</dependency>
@@ -98,12 +98,6 @@
9898
<version>1.1.3</version>
9999
<scope>test</scope>
100100
</dependency>
101-
<dependency>
102-
<groupId>com.google.cloud</groupId>
103-
<artifactId>google-cloud-core</artifactId>
104-
<version>2.3.3</version>
105-
<classifier>tests</classifier>
106-
</dependency>
107101
<dependency>
108102
<groupId>org.springframework.boot</groupId>
109103
<artifactId>spring-boot-test</artifactId>

0 commit comments

Comments
 (0)