Gradle Operations TODEPLETE: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Internal=
=DEPLETE TO=
 
{{Internal|Gradle Operations|Gradle Operations}}
* [[Gradle#Subjects|Gradle]]
 
=Overview=
 
=<span id='General_Command_Line_Options'></span>Command Line=
 
Some command line options have the same effect as setting corresponding properties or environment variables. When a command line option is present, it has precedence over the equivalent properties or environment variables. More details in [[Gradle_Variables_and_Properties#Command_Line_Flags|Gradle Variables and Properties]].
 
gradle --help
 
==<span id='-q'></span>-q, --quiet==
 
Quiet.
 
==-m, --dry-run==
 
Executes a [[Gradle_Task#Dry_Run|dry run]].
 
==-D, --system-prop==
 
{{Internal|Gradle_Variables_and_Properties#System_Properties|System Properties}}
 
==--build-cache==
 
==-x==
 
Execute without the task following -x. For example, if I want to execute a [[#Build_without_Tests|build without tests]]:
 
gradle build -x test
 
or if I want to publish without running the javadoc task:
 
gradle build publish -x javadoc
 
=Runtime Configuration=
 
Various aspects of the runtime configuration are controlled with [[Gradle_Variables_and_Properties#Gradle_Properties|Gradle properties]]:
 
* '''org.gradle.console''': console output coloring and verbosity.
* <span id='org.gradle.debug'></span>'''org.gradle.debug''': starts the JVM in debug mode, listening on port 5005. This is equivalent with adding the following on the JVM command line:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
Also see [[Gradle_Operations#Start_Gradle_in_Debug_Mode|Start Gradle in Debug Mode]].
* '''org.gradle.java.home''', '''org.gradle.jvmargs''' specify the Java home and JVM arguments for the Gradle build process. Also see https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory
* '''org.gradle.logging.level''' https://docs.gradle.org/current/userguide/logging.html#sec:choosing_a_log_level
* '''org.gradle.warning.mode'''
* '''org.gradle.parallel''', '''org.gradle.workers.max''' parallel mode configuration.


=Operations=
=Operations=
==<span id='Start_Gradle_in_Debug_Mode'>Debug a Gradle Script==
This will allow setting breakpoints in the gradle scripts (build.gradle, etc.):
<syntaxhighlight lang='groovy'>
export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
gradle ...
</syntaxhighlight>
Also, important, make sure [[#Do_Not_Use_Gradle_Daemon_to_Run_the_Build|not to use the Gradle daemon]] when debugging the Gradle scripts.
Alternatively, Gradle setting [[#org.gradle.debug|org.gradle.debug]] can be used:
<syntaxhighlight lang='java'>
gradle -Dorg.gradle.debug=true --no-daemon build
</syntaxhighlight>
==Debug a Test Executed with Gradle==
gradle test --debug-jvm
Gradle will suspend execution right before running tests and wait for debugger connection on port 5005.
<font color=darkgray>For selecting specific tests for execution, see https://docs.gradle.org/current/userguide/java_testing.html#simple_name_pattern</font>.


==Start a Project==
==Start a Project==
Line 97: 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}}

Latest revision as of 01:42, 28 March 2021

DEPLETE TO

Gradle Operations

Operations

Start a Project

gradle init

Creates a project structure that includes:

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.

GitHub Playground gradle-init

List Sub-Projects

gradle projects

Inspect Dependencies, Generate Dependency Tree

https://docs.gradle.org/current/userguide/inspecting_dependencies.html

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

Gradle Pass Configuration on Command Line

Pass Configuration via Custom Environment Variables

Pass Configuration via Custom Environment Variables

Artifact Publishing Operations

Artifact Publishing Operations

Command-Line Interface

https://docs.gradle.org/current/userguide/command_line_interface.html

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

Displaying Tasks

properties

Displays project properties, properties added by various plugins and their default values.

gradle properties