Introduction

Target audience : Developers wanting to get started with creating Gradle plugins.

To develop Gradle plugins effectively, a well-configured development environment is essential. A good setup will save you time, reduce frustrations, and ensure the consistency of your builds.

This guide focuses on four essential pillars:
  1. Le JDK(Java Development Kit), because Gradle and JBake run on the JVM.

  2. Un IDEmodern (IntelliJ IDEA) with good Kotlin and Gradle.

  3. Gradlehimself, to initialize the projects.

  4. JBake, the engine of our static site.

Components of the development environment
@startuml
!theme plain
node "Developer Machine" {
  component "JDK (JVM)" as JDK
  component "IntelliJ IDEA" as IDE
  component "Gradle (global)" as Gradle
  component "JBake (global)" as JBake

  IDE --> JDK : utilise
  Gradle --> JDK : utilise
  JBake --> JDK : utilise
}
@enduml

1. The JDK : The Gradle engine

Gradle is an application that runs on the Java Virtual Machine (JVM). Therefore, installing a JDK is an absolute prerequisite.

Which version to choose?

It is recommended to use an LTS (Long-Term Support) version of Java. At present,JDK 17 ou JDK 21are excellent choices.

SDKMAN! is a fantastic tool for managing the versions of many SDKs, including Java and Gradle.

Install SDKMAN!

curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh"

Install a version of the JDK

# Pour lister les versions de Java disponibles sdk list java

# Pour installer Java 17 (par exemple, la distribution Temurin)
sdk install java 17.0.8-tem

Check the installation

java -version

You should see the version you just installed appear.

2. The IDE : IntelliJ IDEA

For the development of Gradle plugins with the Kotlin DSL,IntelliJ IDEAis the tool of choice. Its integration with Gradle and Kotlin is unparalleled.

  • Community Edition :Free and more than enough to start.

  • Ultimate Edition :Paid, it offers advanced features for web and database development.

Download the version that suits you from the JetBrains website: https://www.jetbrains.com/idea/download/

The IDE will automatically detect your files`build.gradle.kts` et settings.gradle.kts, offering you powerful autocompletion, code navigation, and built-in debugging tools.

3. Gradle: The build tool

Even if each project will use its own version of Gradle via the Gradle Wrapper, it is useful to have a global Gradle installation for tasks such as initializing new projects (gradle init)

Installation via SDKMAN!

Just like for the JDK, SDKMAN! simplifies the installation of Gradle.

Install Gradle

sdk install gradle

Check the installation

gradle -v

This command will display the versions of Gradle, Kotlin, Groovy, and JDK used.

4. JBake : The static site generator

JBake is the tool we will use to transform our source files (like this one) into a static website. Having a local installation is convenient for previewing the changes.

Installation via SDKMAN!

Like the other tools, SDKMAN! is the simplest method.

Install JBake

sdk install jbake

Check the installation

jbake -v

This command will display the version of JBake and the Java environment information it uses.

5. The Gradle Wrapper: The absolute best practice

Once your project is created (which we will see in the following article), you should no longer use the global command.gradle. Instead, you will use theGradle Wrapper./gradlew), a script included in your project.

Why?

  • Reproducibility:The Wrapper guarantees that every person working on the project (including your CI/CD server) uses exactly thesame version of Gradle, thus eliminating build errors caused by different environments.

  • Simplicity:No need to install Gradle manually to contribute to a project.

It is enough to clone the repository and run`./gradlew`.

A typical command will look like this:

# Ne pas faire : gradle build
# À faire :
./gradlew build

6. Docker and Portainer: For Reproducible Builds (Optional)

Although not strictly necessary to write a plugin, Docker and Portainer are modern DevOps tools that greatly facilitate the creation of reproducible builds and the management of your environment.

Installation of Docker Engine

Docker allows you to package your application and its dependencies into a container.

Install Docker via the official script:

curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh

Add your user to the group`docker`.

sudo usod -aG docker $USER
docker run hello-world

Manage Docker with Portainer (GUI)

Portainer is a lightweight web interface to manage your Docker containers.

Create a volume for Portainer data :

docker volume create portainer_data

Start the Portainer container:

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

You can now access the Portainer interface on`https://localhost:9443`.

Conclusion

Your environment is now ready! You have a JDK, the most suitable IDE, Gradle, and JBake. With the addition of Docker, you are also ready to create containerized and reproducible builds. This solid foundation will allow you to focus on the essentials: developing powerful and useful plugins.

In the next article, we will use the command`gradle init`to generate the structure of our first plugin project.

Related articles