- 近期在使用gradle,觉得他的task 脚本的方式很灵活,下面记录关于gradle相关的一些东西,后面也会不断补充,但详细解释或者是问题的答案还是建议查看文档
仓库指定
repositories {
mavenLocal()
repositories {
mavenLocal()
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "http://download.oracle.com/maven" }
maven { url "https://palantir.bintray.com/releases" }
}
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "http://download.oracle.com/maven" }
}
指定本地jar包
compile fileTree(dir: project.projectDir.toString() + '/src/main/resources/libs', include: ['*.jar'])
scope相关
详细解释查看文档
dependency-management
spring提供的插件io.spring.dependency-management
是的spring boot可以如maven dependency management
方式一样添加依赖
java doc
gradle Java插件提供了java doc task的功能,配置如下:
configurations {
docletJar
javadocPath
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
compile('org.springframework.boot:spring-boot-starter-log4j:1.3.8.RELEASE')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile fileTree(dir: project.projectDir.toString() + '/src/main/resources/libs', include: ['*.jar'])
//javadoc
docletJar files('/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/lib/tools.jar')
javadocPath('common:3.0-SNAPSHOT')
}
task generateRestApiDocs(type: Javadoc) {
source = sourceSets.main.allJava
options.docletpath = configurations.docletJar.files.asType(List)
options.doclet = "com.eddy.Doclet"
options.classpath = configurations.compile.files.asType(List)
options.classpath.addAll(configurations.javadocPath.files.asType(List))
}
子工程
子工程信息配置在根目录的settings.gradle
文件中,如下方所示:
rootProject.name = 'crawler4j-parent'
include ':crawler4j'
include ':crawler4j-examples-base'
include ':crawler4j-examples-postgres'
project(':crawler4j').projectDir = "$rootDir/crawler4j" as File
project(':crawler4j-examples-base').projectDir = "$rootDir/crawler4j-examples/crawler4j-examples-base" as File
project(':crawler4j-examples-postgres').projectDir = "$rootDir/crawler4j-examples/crawler4j-examples-postgres" as File
build生命周期
生命周期分为:初始化,配置。执行三个不同的阶段。
//settings.gradle
println 'This is executed during the initialization phase.'
//build.gradle
println 'This is executed during the configuration phase.'
task configured {
println 'This is also executed during the configuration phase.'
}
task test {
doLast {
println 'This is executed during the execution phase.'
}
}
task testBoth {
doFirst {
println 'This is executed first during the execution phase.'
}
doLast {
println 'This is executed last during the execution phase.'
}
println 'This is executed during the configuration phase as well.'
}
Flat layout
includeFlat名称即文件夹,并且这些文件夹只能作为子目录的形式存在。