Skip to content

Latest commit

 

History

History
138 lines (92 loc) · 3.13 KB

gradle-cheat-sheet.adoc

File metadata and controls

138 lines (92 loc) · 3.13 KB

Gradle - Cheat Sheet

(Note: The cheat-sheet generally shows Linux/macOS specific commands. For Windows, replace e.g. ./gradlew build with just gradlew build, as the "." will lead to errors)

Running your build with a specific Java version

In addition to fumbling around with your JAVA_HOME env variable, do this:

  1. gradle.properties in your project directory

    // Note: Even on Windows, forward slashes only!!!
    
    org.gradle.java.home=/path_to_jdk_directory
  2. gradle.properties in the .gradle directory in your HOME_DIRECTORY

    // Note: Even on Windows, forward slashes only!!!
    
    org.gradle.java.home=/path_to_jdk_directory

Build a submodule

Instead of doing this:

cd myproject
cd mysubmodule
../gradlew.bat build

do:

cd myproject
./gradlew build -p mysubmodule

// or

./gradlew :mysubmodule:build

Build + Skipping Tests

Not -DskipTests ;)

./gradlew build -x test

Build Spring Boot Docker Image

./gradlew bootBuildImage --imageName=myorg/myapp

Upgrade Gradle Wrapper

// ./gradlew wrapper --gradle-version {version}

./gradlew wrapper --gradle-version 8.4

If that fails, e.g. the new Gradle version is incompatible with your project or your JDK version you will be stuck in an endless loop, because you won’t be able to run the wrapper anymore.

You can then do a "hard-reset" by changing the Gradle wrapper version in this file:

yourprojectgradle\wrapper\gradle-wrapper.properties

## change the version number in the distributionUrl
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip

Gradle Concepts

Gradle Pre-7 <→ Gradle >= 7 mapping

  • compile <→ api (public, i.e. will become a transitive dependency for other modules) and implementation (private, other modules won’t "see" the dependency)

  • testCompile <→ testImplementation

IntelliJ IDEA

Always refresh.

Never forget to click that button, after changing your build.gradle(.kts) file.

mbimage::/images/guides/gradle_refresh_button.png[]

New to Gradle? Want a refresher?

You might enjoy this:

mb_youtube::gKPMKRnnbXU[]

Gradle Configuration Snippets

Gradle + Spring Boot: Custom Dependency Versions

See section Version Properties here: https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html or all possible versions to override.

// in your build.gradle file
ext['jetty.version'] = '11.0.14'

More.

…​soon.

Your help is needed

Please add your own suggestions with a PR and I’ll happily merge them.