Over a million developers have joined DZone.

Debugging Gradle plugins with IntelliJ IDEA

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

When you develop Gradle plugins it's important to have an ability to debug them. There are already a couple of articles online about how to debug Gradle plugins in IDEA with remote debug, but I found it not very convenient since I need to remember JVM options for remote debug and pass it to Gradle. So, I decided to run Gradle from IDEA like a normal Java application. 

For example, you have a project with a structure like:

  • example/
    • build.gradle
  • gradle/
    • wrapper/
      • gradle-wrapper.jar
      • gradle-wrapper.properties
  • src/
    • main/
      • java/
  • build.gradle
  • gradlew
  • gradlew.bat
Where build.gradle and src/ - your plugin's build file and sources, and example/build.gradle - example project with content like:
buildscript {
  repositories {
    ivy {
      artifactPattern "../build/libs/[artifact]-[revision].[ext]"
  dependencies {
    classpath "your.company.name:your-plugin:version"    

apply plugin: 'your-plugin'
Note that the project should have Gradle Wrapper. 

Now we want to add the ability to debug it in IDEA. Add to your plugin's build.gradle these lines:

apply plugin: 'idea'

configurations {

idea {
  module {
    scopes.RUNTIME.plus += [ configurations.gradleRuntime ]

dependencies {
  gradleRuntime files("gradle/wrapper/gradle-wrapper.jar")
Now Gradle Wrapper is available at runtime in IDEA (this will not add dependency to gradle-wrapper to your plugin, it's only for IDEA).

Now, only one thing left - IDEA run configuration. Just create a usual Run Configuration for your application, with the following configuration:


  • MainClass: org.gradle.wrapper.GradleWrapperMain
  • VM options:
  • -DdistributionBase=GRADLE_USER_HOME
  • Program arguments: all that goes after "gradle" command, for example "clean build"
  • Working directory: where you want to run your Gradle build ("example" folder in our case)
  • Before launch: remove "Make" and add Gradle task "jar"
That's it! Now you can debug just created configuration. Easy, isn't it?

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}