- 总项目结构如下,其中有三个文件:
group=com.yawn version=1.0-SNAPSHOT
- settings.gradle 用来说明此项目包含的模块
rootProject.name = 'demo6'
include 'entity'
include 'service'
include 'web'
- build.gradle 管理依赖等,类似于maven的pom文件
allprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
}
// 同 allprojects
subprojects {
repositories {
mavenLocal()
maven {
// maven 私服
url ''
}
mavenCentral()
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.9.1'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
- 此外,此项目下有三个子模块:entity、service、web,三个子模块的依赖关系为web-->service-->entity。三个子模块分别只有build.gradle文件,如下:
- entity
dependencies {
compile ('org.hibernate:hibernate-core:5.2.11.Final') {
// 排除hibernate对self4j的依赖
exclude(group: 'org.slf4j', module: 'selef4j-api')
}
}
- service
dependencies {
compile project(":entity")
}
/*
def createDir = {
path ->
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
}
task makeJavaDir() {
def paths = ['src/main/java', 'src/main/resources', 'src/test/java', 'src/test/resources']
doFirst {
paths.forEach(createDir)
}
}
task makeWebDir() {
def paths = ['src/main/webapp']
doLast {
dependsOn(makeJavaDir)
paths.forEach(createDir)
}
}
*/
- web
apply plugin: 'war'
dependencies {
compile project(":service")
}
/*
def createDir = {
path ->
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
}
task makeJavaDir() {
def paths = ['src/main/java', 'src/main/resources', 'src/test/java', 'src/test/resources']
doFirst {
paths.forEach(createDir)
}
}
task makeWebDir() {
def paths = ['src/main/webapp', 'src/test/webapp']
doLast {
dependsOn 'makeJavaDir'
paths.forEach(createDir)
}
}
*/