使用Gradle构建Spring_Boot应用

使用Gradle构建Spring_Boot应用

项目结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
C:.
.gitignore
.project
│ build.gradle
│ settings.gradle
└─src
├─main
│ ├─java
│ │ └─com
│ │ └─bob
│ │ └─boot
│ │ │ MyApplication.java
│ │ │
│ │ ├─config
│ │ │ MyConfig.java
│ │ │ MyConfigBean.java
│ │ │
│ │ ├─controller
│ │ │ MyController.java
│ │ │
│ │ └─domain
│ │ Person.java
│ │
│ └─resources
│ application.yml
└─test
├─java
└─resources

build.gradle

模板,以后在此模板基础上改就行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
buildscript {
ext {
springBootVersion = '2.1.3.RELEASE'
}
repositories {
maven {
url 'https://repo.spring.io/release'
}
mavenCentral()
}
dependencies {
classpath (
"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}",
"io.spring.gradle:dependency-management-plugin:1.0.7.RELEASE"
)
}
}
apply {
plugin("java")
plugin("maven")
plugin("idea")
plugin("org.springframework.boot")
plugin("io.spring.dependency-management")
}
group 'com.bob'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven {
url 'https://repo.spring.io/release'
}
mavenCentral()
}
dependencies {
compile (
'org.springframework.boot:spring-boot-starter-web',
'org.springframework.boot:spring-boot-loader'
)
}

命令

1
2
3
gradle bootRun
gradle bootJar