1. What is a build tool
A programmable tool that allows you to express automation requirements in executable and ordered tasks.
For example: you need to compile the source code, copy the class file to the specified directory, and then package it into usable software:
Step 1: Compile, Step 2: Copy the Class file to the specified directory, Step 3: Assemble and build. These steps are in order.
These tasks form a directed five-ring graph.
2. Analysis of build tools
Build files: Contains configuration information, external dependencies, dependencies between tasks, etc. required for the build.
Build engine: Process the rules in the build file and execute them in the correct way.
Dependency Manager: Handles dependency definitions declared in build files.
3. Java build tool
1: Ant
2: Maven
3: Gradle
4. Next-generation build tool Gradle
Gradle is based on JVM and uses a Groovy-based language DSL. Learn from ant and maven. Provide support for multi-project builds
5. Install Grade with
JDK1.5 or above, configure GRADLE_HOME, and verify that gradle is correctly installed with gradle -v.
6. Start using the Gradle
Hello World example:
1: Create a build.gradle file.
2: Define an independent atomic operation --task
3: Use groovy syntax to write the following code:
task helloWorld{
doLast{
println 'Hello world'
}
}
Note: tasks and actions are important elements of a DSL. The action doLast indicates the last execution of the task execution (<< also indicates doLast)
task startSession <<{
chant()
}
def chant(){
ant.echo(message: 'repeat after me ...') // Good integration with ant
}
3 .times{
task "yayGradle$it" <<{ // loop 3 times, exposing a parameter it
println 'Gradle rocks'
}
}
yayGradle0.dependsOn startSession // The dependsOn keyword is used to describe dependencies between tasks.
yayGradle2.dependsOn yayGradle1 , yayGradle0
task groupTherapy(dependsOn: yayGradle2)
7. List all tasks
gradle -q tasks
gradle -q tasks --all will list dependencies
8. Multiple tasks execute
gradle -q yayGradle0 groupTherapy first execute yayGradle0 and then execute groupTherapy
//Usually the task is only executed once, in dependencies The same is true in the relationship. In the above sentence, yayGradle0 is only executed once.
9. Run
gradle yG0 gT //gradle yayGradle0 groupTherapy with
camel case abbreviation