Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active April 19, 2020 02:19
Show Gist options
  • Save npodonnell/c6c4b2b1f954fa2a9cb8bad88301f3a2 to your computer and use it in GitHub Desktop.
Save npodonnell/c6c4b2b1f954fa2a9cb8bad88301f3a2 to your computer and use it in GitHub Desktop.
Gradle Cheatsheet

Gradle Cheatsheet

Initalize Gradle in Root Dir (similar to git init):

gradle init

this will create some files:

  • build.gradle -- Gradle build script
  • settings.gradle -- Gradle settings script
  • gradlew -- Gradle wrapper script (UNIX)
  • gradlew.bat -- Gradle wrapper script (Windows)
  • gradle/wrapper/gradle-wrapper.jar -- Gradle wrapper executable JAR
  • gradle/wrapper/gradle-wrapper.properties -- Gradle wrapper configuration properties

List Tasks:

./gradlew tasks

Sync Wrapper Version With Version of System Gradle:

gradle wrapper --gradle-version=5.1.1

This will change the distributionUrl in gradle/wrapper/gradle-wrapper.properties to point to same version as system gradle.

Get Properties:

./gradlew properties

Compile a Java Program:

gradle compileJava

Compile+Test a Java Program:

gradle compileTestJava

Specify Maven Central as a Repository:

Add to build.gradle:

repositories {
    mavenCentral()
}

Add Junit as Dependency:

Add to build.gradle:

dependencies {
    testCompile 'junit:junit:4.12'
}

Build:

gradle build

Plugins

Application Plugin

Application plugin allows invocation of the program with gradle. To enable, add to build.gradle:

apply plugin: 'application'

then specify main class and optional arguments:

mainClassName = "xxx.xxx.xxx.Main"
run.args = ["args", "go", "here"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment