Content Table

Gradle build 脚本

单模块和多模块 Gradle 的构建脚本样例。

单模块 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
apply plugin: 'java'
apply plugin: 'maven'

/* 解决设置版本不起作用问题 */
tasks.withType(JavaCompile) {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}

[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'

////////////////////////////////////////////////////////////////////////////////
// Maven 依赖 //
////////////////////////////////////////////////////////////////////////////////
repositories {
mavenLocal()
mavenCentral()
}

ext {
springVersion = '4.1.1.RELEASE'
springIntegrationVersion = '4.2.4.RELEASE'
}

dependencies {
compile(
"org.springframework:spring-webmvc:$springVersion",
"org.springframework.integration:spring-integration-core:$springIntegrationVersion"
)

testCompile "junit:junit:4.12"
}

多模块 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
allprojects {
group 'com.xtuer'
version '1.0-SNAPSHOT'

apply plugin: 'java'
apply plugin: 'maven'

/* 解决设置版本不起作用问题 */
tasks.withType(JavaCompile) {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}

[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
}

subprojects {
repositories {
mavenLocal()
mavenCentral()
}

ext {
springVersion = '4.1.1.RELEASE'
springIntegrationVersion = '4.2.4.RELEASE'
}

dependencies {
compile(
"org.springframework:spring-webmvc:$springVersion",
"org.springframework.integration:spring-integration-core:$springIntegrationVersion"
)

testCompile "junit:junit:4.12"
}
}

settings.gradle: include 包含子模块的名字

1
2
include 'core'
include 'app'