Gradle Operations TODEPLETE: Difference between revisions
(83 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= | =DEPLETE TO= | ||
{{Internal|Gradle Operations|Gradle Operations}} | |||
=Operations= | =Operations= | ||
Line 12: | Line 9: | ||
Creates a project structure that includes: | Creates a project structure that includes: | ||
* build.gradle | * [[Gradle_Project_and_Build_Script#Overview|build.gradle]] | ||
* settings.gradle | * [[Gradle_Settings_Script_and_Settings_Instance#Overview|settings.gradle]] | ||
* a gradle directory | * a project-level [[Gradle_Configuration#Project-Level_.27gradle.27_Directory|gradle directory]] | ||
* a .gradle directory | * a project-level [[Gradle_Configuration#Project-Level_.27.gradle.27_Directory|.gradle]] directory | ||
* gradlew | * [[Gradle_Concepts#The_Gradle_Wrapper|gradlew]], [[Gradle_Concepts#The_Gradle_Wrapper|gradlew.bat]] | ||
Note that in some cases, the execution flag is not set on gradlew, so you may have to set it manually. | |||
===Gradle Project Initialization Script=== | |||
This is a script that is a little bit more complex than gradle init. The script creates the project root directory, interactively queries project elements, such as the initial package name, etc. It then will will create the initial package and a simple Main class, will initialize build.gradle with the minimal configuration required to build a Java project and it will put in place the run wrapper. | |||
{{External|[https://github.com/NovaOrdis/playground/blob/master/project-template-gradle/gradle-init GitHub Playground gradle-init]}} | |||
==List Sub-Projects== | ==List Sub-Projects== | ||
Line 23: | Line 27: | ||
[[#projects|gradle projects]] | [[#projects|gradle projects]] | ||
==Inspect Dependencies== | ==<span id='Inspect_Dependencies'>Inspect Dependencies, Generate Dependency Tree== | ||
{{External|https://docs.gradle.org/current/userguide/inspecting_dependencies.html}} | {{External|https://docs.gradle.org/current/userguide/inspecting_dependencies.html}} | ||
The full graph of the project's [[ | The full graph of the project's [[Gradle_Dependencies_and_Dependency_Configurations#Dependency|dependencies]] can be rendered. The [[#Identify_Why_a_Specific_Dependency_was_Selected|selection reason and origin for a dependency]] can also be displayed. | ||
To display the dependency trees for all [[ | To display the dependency trees for all [[Gradle_Dependencies_and_Dependency_Configurations#Dependency_Configuration|dependency configurations]] of the project, execute: | ||
gradle -q dependencies | gradle -q dependencies | ||
Line 35: | Line 39: | ||
The result is called a ''dependency report''. Any dependency that could not be resolved is marked with FAILED in red color. Dependencies with the same coordinates that can occur multiple times in the graph are omitted and indicated by an asterisk. Dependencies that had to undergo conflict resolution render the requested and selected version separated by a right arrow character. The dependency report provides the raw list of dependencies but does not explain why they have been selected or which dependency is responsible for pulling them into the graph. These explanations can though be generated, see [[#Identify_Why_a_Specific_Dependency_was_Selected|Identify Why a Specific Dependency was Selected]]. | The result is called a ''dependency report''. Any dependency that could not be resolved is marked with FAILED in red color. Dependencies with the same coordinates that can occur multiple times in the graph are omitted and indicated by an asterisk. Dependencies that had to undergo conflict resolution render the requested and selected version separated by a right arrow character. The dependency report provides the raw list of dependencies but does not explain why they have been selected or which dependency is responsible for pulling them into the graph. These explanations can though be generated, see [[#Identify_Why_a_Specific_Dependency_was_Selected|Identify Why a Specific Dependency was Selected]]. | ||
To display the dependency tree for just one [[ | To display the dependency tree for just one [[Gradle_Dependencies_and_Dependency_Configurations#Dependency_Configuratio|dependency configuration]]: | ||
gradle -q dependencies --configuration <configuration-name> | gradle -q dependencies --configuration <configuration-name> | ||
Line 42: | Line 46: | ||
gradle -q dependencyInsight --dependency <''dependency-name''> [--configuration <''configuration-name''>] | gradle -q dependencyInsight --dependency <''dependency-name''> [--configuration <''configuration-name''>] | ||
==Print the Runtime Classpath== | |||
<syntaxhighlight lang='groovy'> | |||
task printClasspath { | |||
doLast { | |||
configurations.runtimeClasspath.each { print it; print ':' } | |||
} | |||
} | |||
</syntaxhighlight> | |||
Then Gradle must be run with "-q" option to discard extraneous output: | |||
<syntaxhighlight lang='bash'> | |||
gradle -q printClasspath | |||
</syntaxhighlight> | |||
==Run a Specific Test== | |||
gradle test --tests "com.example.MyTests.mySingleTest" | |||
==Do Not Use Gradle Daemon to Run the Build== | |||
gradle --no-daemon ... | |||
Useful when [[#Debug_a_Gradle_Script|debugging Gradle configuration scripts]]. | |||
==Pass Configuration on Command Line== | |||
{{Internal|Gradle Pass Configuration on Command Line#Overview|Gradle Pass Configuration on Command Line}} | |||
==Pass Configuration via Custom Environment Variables== | |||
{{Internal|Passing Configuration to a Gradle Build via Custom Environment Variables#Overview|Pass Configuration via Custom Environment Variables}} | |||
=Artifact Publishing Operations= | |||
{{Internal|Gradle Artifact Publishing Operations#Overview|Artifact Publishing Operations}} | |||
=Command-Line Interface= | =Command-Line Interface= | ||
Line 51: | Line 93: | ||
===build=== | ===build=== | ||
Build without tests | gradle build | ||
Build a [[Gradle_Multi-Project_Builds#Sub-Project|sub-project]]: | |||
gradle :<''sub-project-name''>:build | |||
====Build without Tests==== | |||
Build without tests. Works with simple projects or multi-project builds. | |||
gradle build -x test | gradle build -x test | ||
gradle build -x :''some-project'':test | gradle build -x :''some-project'':test | ||
===projects=== | ===projects=== | ||
Line 66: | Line 112: | ||
===tasks=== | ===tasks=== | ||
{{Internal|Gradle_Task#Displaying_Tasks|Displaying Tasks}} | |||
===properties=== | ===properties=== | ||
Displays project [[ | Displays project [[Gradle_Variables_and_Properties#Overview|properties]], properties added by various plugins and their default values. | ||
gradle properties | gradle properties |
Latest revision as of 01:42, 28 March 2021
DEPLETE TO
Operations
Start a Project
gradle init
Creates a project structure that includes:
- build.gradle
- settings.gradle
- a project-level gradle directory
- a project-level .gradle directory
- gradlew, gradlew.bat
Note that in some cases, the execution flag is not set on gradlew, so you may have to set it manually.
Gradle Project Initialization Script
This is a script that is a little bit more complex than gradle init. The script creates the project root directory, interactively queries project elements, such as the initial package name, etc. It then will will create the initial package and a simple Main class, will initialize build.gradle with the minimal configuration required to build a Java project and it will put in place the run wrapper.
List Sub-Projects
gradle projects
Inspect Dependencies, Generate Dependency Tree
The full graph of the project's dependencies can be rendered. The selection reason and origin for a dependency can also be displayed.
To display the dependency trees for all dependency configurations of the project, execute:
gradle -q dependencies
The result is called a dependency report. Any dependency that could not be resolved is marked with FAILED in red color. Dependencies with the same coordinates that can occur multiple times in the graph are omitted and indicated by an asterisk. Dependencies that had to undergo conflict resolution render the requested and selected version separated by a right arrow character. The dependency report provides the raw list of dependencies but does not explain why they have been selected or which dependency is responsible for pulling them into the graph. These explanations can though be generated, see Identify Why a Specific Dependency was Selected.
To display the dependency tree for just one dependency configuration:
gradle -q dependencies --configuration <configuration-name>
Identify Why a Specific Dependency was Selected
gradle -q dependencyInsight --dependency <dependency-name> [--configuration <configuration-name>]
Print the Runtime Classpath
task printClasspath {
doLast {
configurations.runtimeClasspath.each { print it; print ':' }
}
}
Then Gradle must be run with "-q" option to discard extraneous output:
gradle -q printClasspath
Run a Specific Test
gradle test --tests "com.example.MyTests.mySingleTest"
Do Not Use Gradle Daemon to Run the Build
gradle --no-daemon ...
Useful when debugging Gradle configuration scripts.
Pass Configuration on Command Line
Pass Configuration via Custom Environment Variables
Artifact Publishing Operations
Command-Line Interface
Tasks
build
gradle build
Build a sub-project:
gradle :<sub-project-name>:build
Build without Tests
Build without tests. Works with simple projects or multi-project builds.
gradle build -x test gradle build -x :some-project:test
projects
gradle projects
tasks
properties
Displays project properties, properties added by various plugins and their default values.
gradle properties