能够先参考个人前一篇博客
使用gradle构建java项目html
project下有哪些属性
参考:
https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project.extrapropertiesjava



这里有几个经常使用的属性:git
- allprojects :当前项目及其全部子项目;
- subprojects : 当前项目的全部子项目;
- buildscript : The build script handler for this project. You can use this handler to query details about the build script for this project, and manage the classpath used to compile and execute the project's build script.
- childProjects: 该项目的直接子项目;
- dependencies:用于添加依赖;
- parent:该项目的父项目;
- project : Returns this project. This method is useful in build files to explicitly access project properties and methods. For example, using project.name can express your intent better than using name. This method also allows you to access project properties from a scope where the property may be hidden, such as, for example, from a method or closure.
- projectDir:包含构建脚本build.gradle的目录;
- repositories: 用来设置依赖的仓库来源,repositories
- rootDir : The root directory of this project. The root directory is the project directory of the root project.
- rootProject:跟项目;
task 能实现哪些功能
下面是一些经常使用的基本功能express
复制
task walk(description:'walk') {
doLast {
println 'walk...'
println myName
copy {
into 'demo'
exclude '**/.svn/**'
from('README.md')
}
}
}
删除
task walk(description:'walk') {
doLast {
println 'walk...'
println myName
project.delete {
delete 'README.md'
followSymlinks = true
}
}
}
引入外部的多个jar
compile project.fileTree(dir:'/Users/whuanghkl/code/mygit/io0007/target',include:['*.jar'])
参考:https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N1512Aapi
build.gradle 的执行流程
Lifecycle There is a one-to-one relationship between a Project and a build.gradle file. During build initialisation, Gradle assembles a Project object for each project which is to participate in the build, as follows:app
- Create a Settings instance for the build.
- Evaluate the settings.gradle script, if present, against the Settings object to configure it.
- Use the configured Settings object to create the hierarchy of Project instances.
- Finally, evaluate each Project by executing its build.gradle file, if present, against the project. The projects are evaluated in breadth-wise order, such that a project is evaluated before its child projects. This order can be overridden by calling Project.evaluationDependsOnChildren() or by adding an explicit evaluation dependency using Project.evaluationDependsOn(java.lang.String).
参考: https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N1512A
https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:apply(java.util.Map)svn