Gradle implementation vs. compile dependencies

Gradle version 6 supports both the implementation and compile dependency configurations. Why are they both there and which one should you use? Let’s find out with the two simple rules described in this article. Quick answer: use the implementation configuration and never compile, BUT read on for some important caveats Ways to declare dependencies When declaring Java dependencies in Gradle you provide a dependency configuration to which to assign your dependency....

Published 6 Jun 2020 · 4 min read · Tom Gregory

Gradle Project Properties Best Practices

Gradle project properties provide an easy way to customise builds which may need to run differently in certain situations. In this article you’ll learn the most effective ways to use and set properties, along with some common scenarios you might come across in your Gradle project. UPDATED in July 2021 to reflect recent versions of Gradle. Why do we need project properties in a Gradle build? A Gradle project property is a property that can be accessed in your project’s build....

Published 15 May 2020 · 6 min read · Tom Gregory

Unleashing the Spring Boot Gradle plugin

1. Introduction Spring Boot is a framework to build Java applications with minimal boilerplate code required, whereas Gradle is a highly configurable build automation tool. Using Gradle to build your Spring Boot application is a good approach, but the process is made infinitely easier using the Spring Boot Gradle plugin to provide build functionality specific to Spring Boot. In this article, we’ll explore the most common uses case to get up and running with the Spring Boot Gradle plugin, as well as how to customise it to meet your specific requirements....

Published 8 May 2020 · 6 min read · Tom Gregory

What's the Gradle Wrapper and Why Use it?

The Gradle wrapper is a script you add to your Gradle project and use to execute your build. The advantages are: you don’t need to have Gradle installed on your machine to build the project the wrapper guarantees you’ll be using the version of Gradle required by the project you can easily update the project to a newer version of Gradle, and push those changes to version control so other team members use the newer version Now you’ve got a flavour of what the Gradle wrapper is all about, let’s run through some common use cases....

Published 14 Mar 2020 · 7 min read · Tom Gregory

How to use Gradle api vs. implementation dependencies with the Java Library plugin

In this article you’ll learn the main differences between Gradle api and implementation configurations with a real-world example showing exactly how things work under the covers. The Java Library Plugin is the recommended plugin to use when building libraries to be consumed by another project. It distinguishes between api and implementation dependencies, offering some key benefits for whoever consumes the library. UPDATED in July 2021 to use the latest Gradle version....

Published 29 Feb 2020 · 10 min read · Tom Gregory

Introduction to writing Gradle plugins

Most Gradle builds use at least a few plugins to add extra functionality, so why not make use of this powerful mechanism by writing your own Gradle plugins? In this article, you’ll discover how to encapsulate your own specific Gradle build logic into a plugin, in a simple and reusable way. UPDATED in September 2021 to use Gradle 7.2, Spock 3, and JUnit 5. Gradle plugins overview So what exactly is a Gradle plugin?...

Published 21 Feb 2020 · 11 min read · Tom Gregory

How to do a Maven to Gradle migration on a Java Spring Boot project

If you’re planning to migrate your Maven project to Gradle, you’ll be looking for the path of least resistance to get the job done as easily as possible. In this article you’ll discover the 8 recommended steps to migrate your Java Spring Boot project from Maven to Gradle. Why do a migration to Gradle? If you’re reading this article you probably know why you want to move to Gradle, but some of the reasons probably include:...

Published 14 Feb 2020 · 7 min read · Tom Gregory

Gradle Lifecycle Evaluation Order For Multi-Project Builds

Multi-project builds in Gradle provide a better way to organise your project in the event that your have multiple artifacts to be created or deployed. In simple use cases everything is easy to understand and works without issue. But, as soon as you start to use some more advanced Gradle features we need to look under the cover to better understand how the multiple projects work together within Gradle’s lifecycle....

Published 27 Dec 2019 · 8 min read · Tom Gregory

How to Measure Code Coverage Using SonarQube and Jacoco

Code coverage is a metric that teams use to measure the quality of their tests, and it represents the percentage of production code that has been tested. Discover how to apply the Gradle Jacoco plugin to your project and run a SonarQube scan to generate a code coverage report. UPDATED in November 2021 to reflect SonarQube LTS version switching to 8.9. 1. Overview SonarQube is a tool which aims to improve the quality of your code using static analysis techniques to report:...

Published 13 Dec 2019 · 7 min read · Tom Gregory