能夠先參考個人前一篇博客
使用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