Kaynağa Gözat

Convert guide to gradle

Greg Turnquist 13 yıl önce
ebeveyn
işleme
b3fa3c3522
3 değiştirilmiş dosya ile 73 ekleme ve 98 silme
  1. 17
    20
      README.ftl.md
  2. 55
    78
      README.md
  3. 1
    0
      initial/build.gradle

+ 17
- 20
README.ftl.md Dosyayı Görüntüle

@@ -23,9 +23,9 @@ Set up the project
23 23
 
24 24
 <@create_directory_structure_hello/>
25 25
 
26
-### Create a Maven POM
26
+### Create a Gradle build file
27 27
 
28
-    <@snippet path="pom.xml" prefix="initial"/>
28
+    <@snippet path="build.gradle" prefix="initial"/>
29 29
 
30 30
 Learn what you can do with Spring Boot
31 31
 --------------------------------------
@@ -38,7 +38,7 @@ For example:
38 38
 - Got Thymeleaf? There are a few beans that must always be added to your application context; Spring Boot adds them for you.
39 39
 - Doing multipart file uploads? [MultipartConfigElement](http://docs.oracle.com/javaee/6/api/javax/servlet/MultipartConfigElement.html) is part of the servlet 3.0 spec and lets you define upload parameters in pure Java. With Spring Boot, you don't have to plug a MultipartConfigElement into your servlet. Just define one in your application context and Spring Boot will plug it into Spring MVC's battle-tested `DispatcherServlet`.
40 40
 
41
-These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, if Thymeleaf is on your path, Spring Boot adds a `SpringTemplateEngine` to your application context automatically. But if you define your own `SpringTemplateEnginer` with your own settings, then Spring Boot won't add one. This leaves you in control with little effort on your part.
41
+These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, if Thymeleaf is on your path, Spring Boot adds a `SpringTemplateEngine` to your application context automatically. But if you define your own `SpringTemplateEngine` with your own settings, then Spring Boot won't add one. This leaves you in control with little effort on your part.
42 42
 
43 43
 > **Note:** Spring Boot doesn't generate code or make edits to your files. Instead, when you start up your application, Spring Boot dynamically wires up beans and settings and applies them to your application context.
44 44
 
@@ -70,7 +70,7 @@ Run the application
70 70
 To run the application, execute:
71 71
 
72 72
 ```sh
73
-$ mvn package spring-boot:run
73
+$ ./gradlew build && java -jar build/libs/${project_id}-0.1.0.jar
74 74
 ```
75 75
 
76 76
 You should see some output like this:
@@ -128,11 +128,8 @@ What if you prefer Jetty over Tomcat? Jetty and Tomcat are both compliant servle
128 128
 
129 129
 Add this to your build file's list of dependencies:
130 130
 
131
-```xml
132
-        <dependency>
133
-            <groupId>org.springframework.boot</groupId>
134
-            <artifactId>spring-boot-starter-jetty</artifactId>
135
-        </dependency>
131
+```groovy
132
+    compile("org.springframework.boot:spring-boot-starter-jetty:0.5.0.BUILD-SNAPSHOT")
136 133
 ```
137 134
 
138 135
 Add multipart upload support
@@ -149,7 +146,7 @@ Re-run the application
149 146
 Run the app again:
150 147
 
151 148
 ```sh
152
-$ mvn package spring-boot:run
149
+$ ./gradlew build && java -jar build/libs/${project_id}-0.1.0.jar
153 150
 ```
154 151
 
155 152
 Now check out the output:
@@ -205,18 +202,16 @@ Add consumer-grade services
205 202
 ------------------------------
206 203
 If you are building a web site for your business, you probably need to add some management services. Spring Boot provides several out of the box with its [actuator module][spring-boot-actuator], such as health, audits, beans, and more.
207 204
 
208
-Add this to your pom.xml:
209
-```xml
210
-        <dependency>
211
-            <groupId>org.springframework.boot</groupId>
212
-            <artifactId>spring-boot-starter-actuator</artifactId>
213
-        </dependency>
205
+Add this to your build file's list of dependencies:
206
+
207
+```groovy
208
+    compile("org.springframework.boot:spring-boot-starter-actuator:0.5.0.BUILD-SNAPSHOT")
214 209
 ```
215 210
 
216 211
 Then restart the app:
217 212
 
218 213
 ```sh
219
-$ mvn package spring-boot:run
214
+$ ./gradlew build && java -jar build/libs/${project_id}-0.1.0.jar
220 215
 ```
221 216
 
222 217
 You will see a new set of RESTful end points added to the application. These are management services provided by Spring Boot.
@@ -277,7 +272,7 @@ JAR support and Groovy support
277 272
 ------------------------------
278 273
 The last example showed how Spring Boot makes it easy to wire beans you may not be aware that you need. And it showed how to turn on convenient management services.
279 274
 
280
-But Spring Boot does yet more. It supports not only traditional WAR file deployments, but also makes it easy to put together executable JARs thanks to Spring Boot's loader module. The various guides demonstrate this dual support through the `spring-boot-maven-plugin`. 
275
+But Spring Boot does yet more. It supports not only traditional WAR file deployments, but also makes it easy to put together executable JARs thanks to Spring Boot's loader module. The various guides demonstrate this dual support through the `spring-boot-gradle-plugin`.
281 276
 
282 277
 On top of that, Spring Boot also has Groovy support, allowing you to build web apps with as little as a single file.
283 278
 
@@ -296,7 +291,7 @@ class ThisWillActuallyRun {
296 291
 }
297 292
 ```
298 293
 
299
-> **Note:** It doesn't matter where the file is. You can fit an application that small inside a [single tweet](https://twitter.com/rob_winch/status/364871658483351552)!
294
+> **Note:** It doesn't matter where the file is. You can even fit an application that small inside a [single tweet](https://twitter.com/rob_winch/status/364871658483351552)!
300 295
 
301 296
 Next, [install Spring Boot's CLI](https://github.com/SpringSource/spring-boot#installing-the-cli).
302 297
 
@@ -306,6 +301,8 @@ Run it as follows:
306 301
 $ spring run app.groovy
307 302
 ```
308 303
 
304
+> **Note:** This assumes you shut down the previous application, to avoid a port collision.
305
+
309 306
 From a different terminal window:
310 307
 ```sh
311 308
 $ curl localhost:8080
@@ -316,7 +313,7 @@ Spring Boot dynamically adds key annotations to your code and leverages [Groovy
316 313
 
317 314
 Summary
318 315
 ----------------
319
-Congratulations! You built a simple web application with Spring Boot and learned how it can ramp up your development pace. 
316
+Congratulations! You built a simple web application with Spring Boot and learned how it can ramp up your development pace. You also turned on some handy production services.
320 317
 
321 318
 [spring-boot]: https://github.com/SpringSource/spring-boot
322 319
 [spring-boot-actuator]: https://github.com/SpringSource/spring-boot/blob/master/spring-boot-actuator/README.md

+ 55
- 78
README.md Dosyayı Görüntüle

@@ -11,9 +11,10 @@ What you'll need
11 11
  - About 15 minutes
12 12
  - A favorite text editor or IDE
13 13
  - [JDK 6][jdk] or later
14
- - [Maven 3.0][mvn] or later
14
+ - [Gradle 1.7+][gradle] or [Maven 3.0+][mvn]
15 15
 
16 16
 [jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
17
+[gradle]: http://www.gradle.org/
17 18
 [mvn]: http://maven.apache.org/download.cgi
18 19
 
19 20
 How to complete this guide
@@ -39,7 +40,7 @@ To **skip the basics**, do the following:
39 40
 Set up the project
40 41
 ------------------
41 42
 
42
-First you set up a basic build script. You can use any build system you like when building apps with Spring, but the code you need to work with [Maven](https://maven.apache.org) and [Gradle](http://gradle.org) is included here. If you're not familiar with either, refer to [Building Java Projects with Maven](/guides/gs/maven) or [Building Java Projects with Gradle](/guides/gs/gradle/).
43
+First you set up a basic build script. You can use any build system you like when building apps with Spring, but the code you need to work with [Gradle](http://gradle.org) and [Maven](https://maven.apache.org) is included here. If you're not familiar with either, refer to [Building Java Projects with Gradle](/guides/gs/gradle/) or [Building Java Projects with Maven](/guides/gs/maven).
43 44
 
44 45
 ### Create the directory structure
45 46
 
@@ -50,64 +51,43 @@ In a project directory of your choosing, create the following subdirectory struc
50 51
             └── java
51 52
                 └── hello
52 53
 
53
-### Create a Maven POM
54
-
55
-`pom.xml`
56
-```xml
57
-<?xml version="1.0" encoding="UTF-8"?>
58
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
59
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
60
-    <modelVersion>4.0.0</modelVersion>
61
-
62
-    <groupId>org.springframework</groupId>
63
-    <artifactId>gs-spring-boot</artifactId>
64
-    <version>0.1.0</version>
65
-
66
-    <parent>
67
-        <groupId>org.springframework.boot</groupId>
68
-        <artifactId>spring-boot-starter-parent</artifactId>
69
-        <version>0.5.0.BUILD-SNAPSHOT</version>
70
-    </parent>
71
-
72
-    <dependencies>
73
-        <dependency>
74
-            <groupId>org.springframework.boot</groupId>
75
-            <artifactId>spring-boot-starter-web</artifactId>
76
-        </dependency>
77
-    </dependencies>
78
-
79
-    <properties>
80
-        <start-class>hello.Application</start-class>
81
-    </properties>
82
-
83
-    <build>
84
-        <plugins>
85
-            <plugin> 
86
-                <artifactId>maven-compiler-plugin</artifactId> 
87
-                <version>2.3.2</version> 
88
-            </plugin>
89
-            <plugin>
90
-                <groupId>org.springframework.boot</groupId>
91
-                <artifactId>spring-boot-maven-plugin</artifactId>
92
-            </plugin>
93
-        </plugins>
94
-    </build>
95
-
96
-    <repositories>
97
-        <repository>
98
-            <id>spring-snapshots</id>
99
-            <url>http://repo.springsource.org/libs-snapshot</url>
100
-            <snapshots><enabled>true</enabled></snapshots>
101
-        </repository>
102
-    </repositories>
103
-    <pluginRepositories>
104
-        <pluginRepository>
105
-            <id>spring-snapshots</id>
106
-            <url>http://repo.springsource.org/libs-snapshot</url>
107
-            <snapshots><enabled>true</enabled></snapshots>
108
-        </pluginRepository>
109
-    </pluginRepositories>
110
-</project>
54
+### Create a Gradle build file
55
+
56
+`build.gradle`
57
+```gradle
58
+buildscript {
59
+    repositories {
60
+        maven { url "http://repo.springsource.org/libs-snapshot" }
61
+        mavenLocal()
62
+    }
63
+    dependencies {
64
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT")
65
+    }
66
+}
67
+
68
+apply plugin: 'java'
69
+apply plugin: 'eclipse'
70
+apply plugin: 'idea'
71
+apply plugin: 'spring-boot'
72
+
73
+jar {
74
+    baseName = 'gs-spring-boot'
75
+    version =  '0.1.0'
76
+}
77
+
78
+repositories {
79
+    mavenCentral()
80
+    maven { url "http://repo.springsource.org/libs-snapshot" }
81
+}
82
+
83
+dependencies {
84
+    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT")
85
+    testCompile("junit:junit:4.11")
86
+}
87
+
88
+task wrapper(type: Wrapper) {
89
+    gradleVersion = '1.7'
90
+}
111 91
 ```
112 92
 
113 93
 Learn what you can do with Spring Boot
@@ -121,7 +101,7 @@ For example:
121 101
 - Got Thymeleaf? There are a few beans that must always be added to your application context; Spring Boot adds them for you.
122 102
 - Doing multipart file uploads? [MultipartConfigElement](http://docs.oracle.com/javaee/6/api/javax/servlet/MultipartConfigElement.html) is part of the servlet 3.0 spec and lets you define upload parameters in pure Java. With Spring Boot, you don't have to plug a MultipartConfigElement into your servlet. Just define one in your application context and Spring Boot will plug it into Spring MVC's battle-tested `DispatcherServlet`.
123 103
 
124
-These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, if Thymeleaf is on your path, Spring Boot adds a `SpringTemplateEngine` to your application context automatically. But if you define your own `SpringTemplateEnginer` with your own settings, then Spring Boot won't add one. This leaves you in control with little effort on your part.
104
+These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, if Thymeleaf is on your path, Spring Boot adds a `SpringTemplateEngine` to your application context automatically. But if you define your own `SpringTemplateEngine` with your own settings, then Spring Boot won't add one. This leaves you in control with little effort on your part.
125 105
 
126 106
 > **Note:** Spring Boot doesn't generate code or make edits to your files. Instead, when you start up your application, Spring Boot dynamically wires up beans and settings and applies them to your application context.
127 107
 
@@ -202,7 +182,7 @@ Run the application
202 182
 To run the application, execute:
203 183
 
204 184
 ```sh
205
-$ mvn package spring-boot:run
185
+$ ./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
206 186
 ```
207 187
 
208 188
 You should see some output like this:
@@ -260,11 +240,8 @@ What if you prefer Jetty over Tomcat? Jetty and Tomcat are both compliant servle
260 240
 
261 241
 Add this to your build file's list of dependencies:
262 242
 
263
-```xml
264
-        <dependency>
265
-            <groupId>org.springframework.boot</groupId>
266
-            <artifactId>spring-boot-starter-jetty</artifactId>
267
-        </dependency>
243
+```groovy
244
+    compile("org.springframework.boot:spring-boot-starter-jetty:0.5.0.BUILD-SNAPSHOT")
268 245
 ```
269 246
 
270 247
 Add multipart upload support
@@ -321,7 +298,7 @@ Re-run the application
321 298
 Run the app again:
322 299
 
323 300
 ```sh
324
-$ mvn package spring-boot:run
301
+$ ./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
325 302
 ```
326 303
 
327 304
 Now check out the output:
@@ -377,18 +354,16 @@ Add consumer-grade services
377 354
 ------------------------------
378 355
 If you are building a web site for your business, you probably need to add some management services. Spring Boot provides several out of the box with its [actuator module][spring-boot-actuator], such as health, audits, beans, and more.
379 356
 
380
-Add this to your pom.xml:
381
-```xml
382
-        <dependency>
383
-            <groupId>org.springframework.boot</groupId>
384
-            <artifactId>spring-boot-starter-actuator</artifactId>
385
-        </dependency>
357
+Add this to your build file's list of dependencies:
358
+
359
+```groovy
360
+    compile("org.springframework.boot:spring-boot-starter-actuator:0.5.0.BUILD-SNAPSHOT")
386 361
 ```
387 362
 
388 363
 Then restart the app:
389 364
 
390 365
 ```sh
391
-$ mvn package spring-boot:run
366
+$ ./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
392 367
 ```
393 368
 
394 369
 You will see a new set of RESTful end points added to the application. These are management services provided by Spring Boot.
@@ -449,7 +424,7 @@ JAR support and Groovy support
449 424
 ------------------------------
450 425
 The last example showed how Spring Boot makes it easy to wire beans you may not be aware that you need. And it showed how to turn on convenient management services.
451 426
 
452
-But Spring Boot does yet more. It supports not only traditional WAR file deployments, but also makes it easy to put together executable JARs thanks to Spring Boot's loader module. The various guides demonstrate this dual support through the `spring-boot-maven-plugin`. 
427
+But Spring Boot does yet more. It supports not only traditional WAR file deployments, but also makes it easy to put together executable JARs thanks to Spring Boot's loader module. The various guides demonstrate this dual support through the `spring-boot-gradle-plugin`.
453 428
 
454 429
 On top of that, Spring Boot also has Groovy support, allowing you to build web apps with as little as a single file.
455 430
 
@@ -468,7 +443,7 @@ class ThisWillActuallyRun {
468 443
 }
469 444
 ```
470 445
 
471
-> **Note:** It doesn't matter where the file is. You can fit an application that small inside a [single tweet](https://twitter.com/rob_winch/status/364871658483351552)!
446
+> **Note:** It doesn't matter where the file is. You can even fit an application that small inside a [single tweet](https://twitter.com/rob_winch/status/364871658483351552)!
472 447
 
473 448
 Next, [install Spring Boot's CLI](https://github.com/SpringSource/spring-boot#installing-the-cli).
474 449
 
@@ -478,6 +453,8 @@ Run it as follows:
478 453
 $ spring run app.groovy
479 454
 ```
480 455
 
456
+> **Note:** This assumes you shut down the previous application, to avoid a port collision.
457
+
481 458
 From a different terminal window:
482 459
 ```sh
483 460
 $ curl localhost:8080
@@ -488,7 +465,7 @@ Spring Boot dynamically adds key annotations to your code and leverages [Groovy
488 465
 
489 466
 Summary
490 467
 ----------------
491
-Congratulations! You built a simple web application with Spring Boot and learned how it can ramp up your development pace. 
468
+Congratulations! You built a simple web application with Spring Boot and learned how it can ramp up your development pace. You also turned on some handy production services.
492 469
 
493 470
 [spring-boot]: https://github.com/SpringSource/spring-boot
494 471
 [spring-boot-actuator]: https://github.com/SpringSource/spring-boot/blob/master/spring-boot-actuator/README.md

+ 1
- 0
initial/build.gradle Dosyayı Görüntüle

@@ -11,6 +11,7 @@ buildscript {
11 11
 apply plugin: 'java'
12 12
 apply plugin: 'eclipse'
13 13
 apply plugin: 'idea'
14
+apply plugin: 'spring-boot'
14 15
 
15 16
 jar {
16 17
     baseName = 'gs-spring-boot'