Skip to content

Latest commit

 

History

History
221 lines (148 loc) · 4.21 KB

gradle.md

File metadata and controls

221 lines (148 loc) · 4.21 KB

Gradle

https://gradle.org/

Newer JVM build system written in Groovy with a nicer build configuration file build.gradle.

Good replacement for Maven.

Key Points

  • good docs
  • good plugin support
  • easy to work with
  • Gradle Wrapper ./gradlew shell script for guaranteed Gradle version download for compatibility

See Gradle cookbook.

Gradle Daemon runs in the background:

gradle --stop

or if changing versions, gradle only manages its current version, so:

pkill -f org.gradle.launcher.daemon.bootstrap.GradleDaemon

Plugins

Adds support for compiling languages:

apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'groovy'

adds install task for publishing to Maven repo, generates poms under build/poms/:

apply plugin: 'maven'

There is also a factory method for generating the pom without uploading to a Maven repo:

see https:docs.gradle.org/current/userguide/maven_plugin.html#N13A3E

executable jar:

apply plugin: 'application'
mainClassName = 'com.linkedin.harisekhon.Main'

Uber jar

  • ShadowJar
  • Application plugin

SonarQube

http:docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle

A build.gradle plugin.

Configure ~/.gradle/gradle.properties:

systemProp.sonar.host.url
# optionally
systemProp.sonar.login
systemProp.sonar.password
gradle sonarqube -Dsonar.host.url=http:sonar.mycompany.com \
                 -Dsonar.jdbc.password=myPassword \
                 -Dsonar.verbose=true

VersionEye

See HariSekhon/lib-java:

build.gradle:

plugins { id "org.standardout.versioneye" version "1.4.0" }

gradle.properties:

versioneye.projectid=<long_num_from_project_page_no_spaces>
gradle versionEyeUpdate

Gradle Wrapper

Generates:

  • gradlew / gradlew.bat scripts
  • gradle/wrapper/gradle-wrapper.jar
    • stub program that downloads the exact same version of gradle recorded in gradle-wrapper.properties as you just ran or the version specifed by --gradle-version eg. 2.0
  • gradle/wrapper/gradle-wrapper.properties

All of the above should be checked in to revision control.

gradle wrapper
git add -f gradlew gradlew.bat gradle/
git ci -m "added gradle wrapper"

In future gradle commands just substitute gradle for ./gradlew.

This downloads same gradle version as original builder to

.gradle/wrapper/dists/gradle-2.11-bin/

and uses that:

./gradlew ...

build.gradle

Create build.gradle - will port existing pom.xml if found:

gradle init
  • must specify rootProject.name otherwise taken to be name of containing directory which can be random on CI systems
  • name = property is read-only in build.gradle

settings.gradle:

rootProject.name = 'harisekhon-utils'

HariSekhon/Templates - build.gradle

build.gradle structure:

  • project
    • tasks
gradle --help

Show list of available tasks:

gradle tasks

Gradle build is equivalent to gradle check assemble - creates artifacts in build/libs/:

gradle build

Requires maven plugin - create artifacts + installs to ~/.m2/repository:

gradle install
  • build/
    • dependencies_cache
    • libs - find jar artifact here
    • reports/tests - open index.html for breakdown of unit tests

All verification tasks, including test. Some plugins add more checks (eg. CheckStyle):

gradle check

Create archives / jars:

gradle assemble

Show tree graph of dependencies for different stages, test:

gradle dependencies

Readme Card

Ported from private Knowledge Base page 2016+