Renato Ivancic - Software Engineer

Background image

Gradle build tool

Backend

Gradle

Gradle is a dependency management, and a build automation tool. It is based on Groovy which provides a DSL for writing build script. Plugins are used to provide compilation and other extended features. Gradle build steps are called tasks.

The Latest version is 6.4. Form 6.3 on, java 14 is also supported.

Wrapper

The recommended way to execute any Gradle build is with the help of the Gradle Wrapper (in short just “Wrapper”). The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary.

Gradle wrapper standardizes project with a given Gradle version, which leads to more reliable and robust builds.

To make the Wrapper files available to other developers and execution environments you’ll need to check them into version control. All Wrapper files including the JAR file are very small in size. Adding the JAR file to version control is expected.

.
├── build.gradle
├── settings.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
└── gradlew.bat

Investigating dependencies

Ever wonder why your gradle build is failing because unresolved or not compatible dependencies. Where to get started? To have a visual graph and information about all dependencies in front of your eyes is essential. Here dependencies command should be your answer.

Gradle provides sufficient tooling to navigate large dependency graphs and mitigate situations that can lead to dependency hell.

List all dependencies

By default, dependencies gets listed for all the configurations. This can output a lot of unnecessary information.

For this you can list all of the configurations first.

./gradlew --console plain dependencies | fgrep ' - '

Then you list all the dependencies for this particular configuration

./gradlew dependencies --configuration compileClasspath

In the following result we can clearly see the graph of dependencies that will be used for compiling java project

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

compileClasspath - Compile classpath for source set 'main'.
+--- com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20191001.1
|    \--- com.google.guava:guava:27.1-jre
|         +--- com.google.guava:failureaccess:1.0.1
|         +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|         +--- com.google.code.findbugs:jsr305:3.0.2
|         +--- org.checkerframework:checker-qual:2.5.2
|         +--- com.google.errorprone:error_prone_annotations:2.2.0
|         +--- com.google.j2objc:j2objc-annotations:1.1
|         \--- org.codehaus.mojo:animal-sniffer-annotations:1.17
+--- org.apache.commons:commons-lang3:3.10
+--- org.springframework.boot:spring-boot-starter-thymeleaf -> 2.2.6.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:2.2.6.RELEASE
|    |    +--- org.springframework.boot:spring-boot:2.2.6.RELEASE
|    |    |    +--- org.springframework:spring-core:5.2.5.RELEASE
...

List specific dependency

You can also resolve a graph for one specific dependency.

./gradlew -q dependencyInsight --dependency aws-java-sdk-sqs --configuration compileClasspath

Sources

Gradle

Gradle Dependencies

Gradle Configurations

#Gradle #Build tool