Kaynağa Gözat

Convert guide to gradle

Greg Turnquist 13 yıl önce
ebeveyn
işleme
e22191c0a7
3 değiştirilmiş dosya ile 65 ekleme ve 88 silme
  1. 4
    4
      README.ftl.md
  2. 61
    81
      README.md
  3. 0
    3
      initial/build.gradle

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

43
 
43
 
44
 <@create_directory_structure_hello/>
44
 <@create_directory_structure_hello/>
45
 
45
 
46
-### Create a Maven POM
46
+### Create a Gradle build file
47
 
47
 
48
-    <@snippet path="pom.xml" prefix="initial"/>
48
+    <@snippet path="build.gradle" prefix="initial"/>
49
 
49
 
50
 <@bootstrap_starter_pom_disclaimer/>
50
 <@bootstrap_starter_pom_disclaimer/>
51
 
51
 
119
 
119
 
120
 <@build_an_executable_jar_subhead/>
120
 <@build_an_executable_jar_subhead/>
121
 
121
 
122
-<@build_an_executable_jar/>
122
+<@build_an_executable_jar_with_gradle/>
123
 
123
 
124
-<@run_the_application_with_maven module="service"/>
124
+<@run_the_application_with_gradle module="service"/>
125
 
125
 
126
 Logging output is displayed. The service should be up and running within a few seconds.
126
 Logging output is displayed. The service should be up and running within a few seconds.
127
 
127
 

+ 61
- 81
README.md Dosyayı Görüntüle

30
  - About 15 minutes
30
  - About 15 minutes
31
  - A favorite text editor or IDE
31
  - A favorite text editor or IDE
32
  - [JDK 6][jdk] or later
32
  - [JDK 6][jdk] or later
33
- - [Maven 3.0][mvn] or later
33
+ - [Gradle 1.7+][gradle] or [Maven 3.0+][mvn]
34
 
34
 
35
 [jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
35
 [jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
36
+[gradle]: http://www.gradle.org/
36
 [mvn]: http://maven.apache.org/download.cgi
37
 [mvn]: http://maven.apache.org/download.cgi
37
 
38
 
38
 
39
 
59
 Set up the project
60
 Set up the project
60
 ------------------
61
 ------------------
61
 
62
 
62
-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/).
63
+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).
63
 
64
 
64
 ### Create the directory structure
65
 ### Create the directory structure
65
 
66
 
70
             └── java
71
             └── java
71
                 └── hello
72
                 └── hello
72
 
73
 
73
-### Create a Maven POM
74
-
75
-`pom.xml`
76
-```xml
77
-<?xml version="1.0" encoding="UTF-8"?>
78
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
79
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
80
-    <modelVersion>4.0.0</modelVersion>
81
-
82
-    <groupId>org.springframework</groupId>
83
-    <artifactId>gs-rest-service</artifactId>
84
-    <version>0.1.0</version>
85
-
86
-    <parent>
87
-        <groupId>org.springframework.boot</groupId>
88
-        <artifactId>spring-boot-starter-parent</artifactId>
89
-        <version>0.5.0.BUILD-SNAPSHOT</version>
90
-    </parent>
91
-
92
-    <dependencies>
93
-        <dependency>
94
-            <groupId>org.springframework.boot</groupId>
95
-            <artifactId>spring-boot-starter-web</artifactId>
96
-        </dependency>
97
-        <dependency>
98
-            <groupId>com.fasterxml.jackson.core</groupId>
99
-            <artifactId>jackson-databind</artifactId>
100
-        </dependency>
101
-    </dependencies>
102
-
103
-    <build>
104
-        <plugins>
105
-            <plugin>
106
-                <artifactId>maven-compiler-plugin</artifactId>
107
-                <version>2.3.2</version>
108
-            </plugin>
109
-        </plugins>
110
-    </build>
111
-
112
-    <repositories>
113
-        <repository>
114
-            <id>spring-snapshots</id>
115
-            <url>http://repo.springsource.org/libs-snapshot</url>
116
-            <snapshots><enabled>true</enabled></snapshots>
117
-        </repository>
118
-    </repositories>
119
-    <pluginRepositories>
120
-        <pluginRepository>
121
-            <id>spring-snapshots</id>
122
-            <url>http://repo.springsource.org/libs-snapshot</url>
123
-            <snapshots><enabled>true</enabled></snapshots>
124
-        </pluginRepository>
125
-    </pluginRepositories>
126
-</project>
74
+### Create a Gradle build file
75
+
76
+`build.gradle`
77
+```gradle
78
+buildscript {
79
+    repositories {
80
+        maven { url "http://repo.springsource.org/libs-snapshot" }
81
+        mavenLocal()
82
+    }
83
+}
84
+
85
+apply plugin: 'java'
86
+apply plugin: 'eclipse'
87
+apply plugin: 'idea'
88
+
89
+jar {
90
+    baseName = 'gs-rest-service'
91
+    version =  '0.1.0'
92
+}
93
+
94
+repositories {
95
+    mavenCentral()
96
+    maven { url "http://repo.springsource.org/libs-snapshot" }
97
+}
98
+
99
+dependencies {
100
+    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.BUILD-SNAPSHOT")
101
+    compile("com.fasterxml.jackson.core:jackson-databind")
102
+    testCompile("junit:junit:4.11")
103
+}
104
+
105
+task wrapper(type: Wrapper) {
106
+    gradleVersion = '1.7'
107
+}
127
 ```
108
 ```
128
 
109
 
129
 This guide is using [Spring Boot's starter POMs](/guides/gs/spring-boot/).
110
 This guide is using [Spring Boot's starter POMs](/guides/gs/spring-boot/).
130
 
111
 
131
-Note to experienced Maven users who are unaccustomed to using an external parent project: you can take it out later, it's just there to reduce the amount of code you have to write to get started.
132
-
133
 
112
 
134
 <a name="initial"></a>
113
 <a name="initial"></a>
135
 Create a resource representation class
114
 Create a resource representation class
263
 
242
 
264
 Now that your `Application` class is ready, you simply instruct the build system to create a single, executable jar containing everything. This makes it easy to ship, version, and deploy the service as an application throughout the development lifecycle, across different environments, and so forth.
243
 Now that your `Application` class is ready, you simply instruct the build system to create a single, executable jar containing everything. This makes it easy to ship, version, and deploy the service as an application throughout the development lifecycle, across different environments, and so forth.
265
 
244
 
266
-Add the following configuration to your existing Maven POM:
267
-
268
-`pom.xml`
269
-```xml
270
-    <properties>
271
-        <start-class>hello.Application</start-class>
272
-    </properties>
273
-
274
-    <build>
275
-        <plugins>
276
-            <plugin>
277
-                <groupId>org.springframework.boot</groupId>
278
-                <artifactId>spring-boot-maven-plugin</artifactId>
279
-            </plugin>
280
-        </plugins>
281
-    </build>
282
-```
245
+Add the following configuration to your existing Gradle build file:
283
 
246
 
284
-The `start-class` property tells Maven to create a `META-INF/MANIFEST.MF` file with a `Main-Class: hello.Application` entry. This entry enables you to run it with `mvn spring-boot:run` (or simply run the jar itself with `java -jar`).
247
+`build.gradle`
248
+```groovy
249
+buildscript {
250
+    ...
251
+    dependencies {
252
+        classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT")
253
+    }
254
+}
285
 
255
 
286
-The [Spring Boot maven plugin][spring-boot-maven-plugin] collects all the jars on the classpath and builds a single "über-jar", which makes it more convenient to execute and transport your service.
256
+apply plugin: 'spring-boot'
257
+```
258
+
259
+The [Spring Boot gradle plugin][spring-boot-gradle-plugin] collects all the jars on the classpath and builds a single "über-jar", which makes it more convenient to execute and transport your service.
260
+It also searches for the `public static void main()` method to flag as a runnable class.
287
 
261
 
288
 Now run the following command to produce a single executable JAR file containing all necessary dependency classes and resources:
262
 Now run the following command to produce a single executable JAR file containing all necessary dependency classes and resources:
289
 
263
 
290
 ```sh
264
 ```sh
291
-$ mvn package
265
+$ ./gradlew build
266
+```
267
+
268
+Now you can run the JAR by typing:
269
+
270
+```sh
271
+$ java -jar build/libs/gs-rest-service-0.1.0.jar
292
 ```
272
 ```
293
 
273
 
294
-[spring-boot-maven-plugin]: https://github.com/SpringSource/spring-boot/tree/master/spring-boot-tools/spring-boot-maven-plugin
274
+[spring-boot-gradle-plugin]: https://github.com/SpringSource/spring-boot/tree/master/spring-boot-tools/spring-boot-gradle-plugin
295
 
275
 
296
 > **Note:** The procedure above will create a runnable JAR. You can also opt to [build a classic WAR file](/guides/gs/convert-jar-to-war/) instead.
276
 > **Note:** The procedure above will create a runnable JAR. You can also opt to [build a classic WAR file](/guides/gs/convert-jar-to-war/) instead.
297
 
277
 
298
 Run the service
278
 Run the service
299
 -------------------
279
 -------------------
300
-Run your service using the spring-boot plugin at the command line:
280
+Run your service at the command line:
301
 
281
 
302
 ```sh
282
 ```sh
303
-$ mvn spring-boot:run
283
+$ ./gradlew clean build && java -jar build/libs/gs-rest-service-0.1.0.jar
304
 ```
284
 ```
305
 
285
 
306
 
286
 

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

3
         maven { url "http://repo.springsource.org/libs-snapshot" }
3
         maven { url "http://repo.springsource.org/libs-snapshot" }
4
         mavenLocal()
4
         mavenLocal()
5
     }
5
     }
6
-    dependencies {
7
-        classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT")
8
-    }
9
 }
6
 }
10
 
7
 
11
 apply plugin: 'java'
8
 apply plugin: 'java'