转载自Gradle官方文档:
https://docs.gradle.org/3.3/userguide/java_plugin.html
The Java plugin adds a number of tasks to your project, as shown below.
Table 47.1. Java plugin - tasks
Task name | Depends on | Type | Description |
compileJava | All tasks which produce the compile classpath. This includes the jar task for project dependencies included in the compile configuration. | JavaCompile | Compiles production Java source files using javac. |
processResources | - | Copy | Copies production resources into the production resources directory. |
classes | The compileJava task and the processResources task. Some plugins add additional compilation tasks. | Task | Assembles the production classes and resources directories. |
compileTestJava | compile , plus all tasks which produce the test compile classpath. | JavaCompile | Compiles test Java source files using javac. |
processTestResources | - | Copy | Copies test resources into the test resources directory. |
testClasses | compileTestJava task and processTestResources task. Some plugins add additional test compilation tasks. | Task | Assembles the test classes and resources directories. |
jar | compile | Jar | Assembles the JAR file |
javadoc | compile | Javadoc | Generates API documentation for the production Java source, using Javadoc |
test | compile , compileTest , plus all tasks which produce the test runtime classpath. | Test | Runs the unit tests using JUnit or TestNG. |
uploadArchives | The tasks which produce the artifacts in the archives configuration, including jar . | Upload | Uploads artifacts in the archives configuration, including the JAR file. |
clean | - | Delete | Deletes the project build directory. |
clean | - | Delete | Deletes files created by specified task. cleanJar will delete the JAR file created by the jar task, and cleanTest will delete the test results created by the test task. |
For each source set you add to the project, the Java plugin adds the following compilation tasks:
Table 47.2. Java plugin - source set tasks
Task name | Depends on | Type | Description |
compile | All tasks which produce the source set's compile classpath. | JavaCompile | Compiles the given source set's Java source files using javac. |
process | - | Copy | Copies the given source set's resources into the resources directory. |
| The compile task and the process task. Some plugins add additional compilation tasks for the source set. | Task | Assembles the given source set's classes and resources directories. |
The Java plugin also adds a number of tasks which form a lifecycle for the project:
Table 47.3. Java plugin - lifecycle tasks
Task name | Depends on | Type | Description |
assemble | All archive tasks in the project, including jar . Some plugins add additional archive tasks to the project. | Task | Assembles all the archives in the project. |
check | All verification tasks in the project, including test . Some plugins add additional verification tasks to the project. | Task | Performs all verification tasks in the project. |
build | check and assemble | Task | Performs a full build of the project. |
buildNeeded | build and buildNeeded tasks in all project lib dependencies of thetestRuntime configuration. | Task | Performs a full build of the project and all projects it depends on. |
buildDependents | build and buildDependents tasks in all projects with a project lib dependency on this project in a testRuntime configuration. | Task | Performs a full build of the project and all projects which depend on it. |
build | The tasks which produce the artifacts in configuration ConfigName . | Task | Assembles the artifacts in the specified configuration. The task is added by the Base plugin which is implicitly applied by the Java plugin. |
upload | The tasks which uploads the artifacts in configuration ConfigName . | Upload | Assembles and uploads the artifacts in the specified configuration. The task is added by the Base plugin which is implicitly applied by the Java plugin. |
The following diagram shows the relationships between these tasks.