Debug your plug-in

1. Create the configuration

Click Edit Configurations, click the +, and then click Remote.

Generate a Remote Debug configuration. You can change the Name of the Remote Debug configuration, but do not change the Name circled in red.

2. Create a debug environment

Start Gradle remote debugging in the root directory of the project, as shown below:

export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Copy the code

3. Debugging phase

Break the plug-in you want to debug, and start executing the plug-in in the root directory, as shown below:

./gradlew task --no-daemon -Dorg.gradle.debug=true
Copy the code

Listening for transport dt_socket at address: 5005 is displayed, indicating that the debugging environment has been created.

Next, we need to click on debug’s breakpoint to start debugging.

4. Finish debugging

When debugging is complete, we need to turn off remote debugging and empty GRADLE_OPTS.

export GRADLE_OPTS=""
Copy the code

Debugging third-party plug-ins

Third-party plug-ins generally do not have the source code, so we need to import the source code of the third-party plug-in before starting the debugging steps described above. Third party plug-ins are declared in the build.gradle script in the project directory using classpath, as shown below:

If we need to debug the above plug-in, we need to change the classpath to implementation, i.e. :

implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Copy the code

Place this dependency under the dependency of the module to be debugged, sync synchronizes, and then use the preceding steps to start debugging.

When debugging a third-party plug-in, the task was interrupted before the breakpoint was reached. The error message is related to importing the dependency of the plug-in. In this case, you can comment out the dependency, and then start debugging, even if there is no cache, breakpoint will succeed. But it didn’t work the second time, so I don’t know why.

Reference documentation

Gradle plugin development series Gradle plugin debugging methods

2, # How to debug third-party Gradle Plugin without breakpoint