Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

debugging - Debug Gradle plugins with IntelliJ

Problem

I want to use the interactive debugger with IntelliJ. Unfortunately, I can't convince IntelliJ to load and compile the plugin. However, I can do gradle clean build and the plugin builds and runs its tests as expected.

Specifically, I'm trying to debug local changes to gradle-js-plugin and IntelliJ says it can't find com.google.javascript.jscomp.CompilerOptions as well as spock.lang.Specification. (I'm thinking maybe it's something about the way they are loaded, but that's a guess.)


Things I've tried

NOTE: I didn't revert any processes between steps.

0. My First Guess

I noticed a howto on docs.codehaus.org. IntelliJ couldn't find org.gradle.launcher.GradleMain, so I've adapted it to use GradleLauncher with the following:

import org.gradle.GradleLauncher

class GradleScriptRunner {
    public static void main(String[] args) {
        GradleLauncher.newInstance(
            "-p", 
            "/path/to/gradle-js-plugin/src/test/resources/build.gradle", 
            "clean assemble"
        )
    }
}

Per GradleLauncher's documentation.

Outcome: IntelliJ won't compile the project.


1. Per Peter Niederwieser's answer Fix idea project & debug via plugin

Steps

  1. ~# cd /path/to/gradle-js-plugin && gradle cleanIdea idea
  2. Opened the newly created project and attempted to debug using the ScriptRunner from step 0.

Outcome: Project compiles (yay!), but I can only hit breakpoints in GradleScriptRunner.groovy.


2. Per Peter Niederwieser's answer run gradle CLI w/ special options

1 & 2. Merged for clarity:

~# export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
~# gradle clean assemble
Listening for transport dt_socket at address: 5005
  1. Configure IntelliJ to connect to this port and start debugging (see image): How I configured the debugger

For this step I tried the following .gradle file configurations:

1. Use only build.gradle

--build.gradle--

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        compile findProject "/path/to/gradle-js-plugin"
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

Outcome:

FAILURE: Build failed with an exception.

* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 13

* What went wrong:
A problem occurred evaluating root project 'resources'.
> No such property: findProject for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8 mins 50.498 secs

2. Use both build.gradle and settings.gradle

--settings.gradle--

include "/path/to/gradle-js-plugin"

--build.gradle--

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

Outcome:

FAILURE: Build failed with an exception.

* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 5

* What went wrong:
A problem occurred evaluating root project 'resources'.
> Plugin with id 'js' not found.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 13.553 secs


My Setup

Gradle

~# gradle -v
------------------------------------------------------------
Gradle 1.0
------------------------------------------------------------

Gradle build time: Tuesday, June 12, 2012 12:56:21 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.7.0_04 (Oracle Corporation 23.0-b21)
OS: Linux 3.2.0-2-amd64 amd64

Java

~# java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

IntelliJ

IntelliJ IDEA Ultimate 117.499 w/ Bundled Gradle plugin

Hoping for

Any tips that'll get me into debug mode within the plugin.

question from:https://stackoverflow.com/questions/11129401/debug-gradle-plugins-with-intellij

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was able to debug gradle sources (including plugins) using -Dorg.gradle.debug=true (found on gradle forum):

  1. Stop daemons if any:

    ./gradlew --stop

  2. Run

    ./gradlew <task> --no-daemon -Dorg.gradle.debug=true

  3. Connect remotely to gradle process (port 5005) - if using IntelliJ IDEA, see OP's image above

It should stop on breakpoints now.


BTW, I have created a separate IntelliJ IDEA project for gradle sources. Since I use gradle wrapper, I have grabbed the sources from

~/.gradle/wrapper/dists/gradle-1.11-all/7qd8qq8te5j4f5q9aaei3gh3lj/gradle-1.11/src

In IDEA I did File->Import Project, then selected the above path, then - "Create project from existing sources". Hit Next couple of times (made sure I didn't include any jars from lib/plugins directory, since IDEA would complain that most project files already exist).

I then created a remote debug configuration in that IDEA project and used it for debugging gradle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...