使用IntelliJ调试Gradle插件 [英] Debug Gradle plugins with IntelliJ

查看:153
本文介绍了使用IntelliJ调试Gradle插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我想使用IntelliJ的交互式调试器。 不幸的是,我无法说服IntelliJ加载编译插件。然而,我可以做 gradle clean build ,并且插件构建并按预期运行测试。



具体来说,我试图调试本地的更改 gradle-js-plugin 和IntelliJ说它找不到 com.google.javascript.jscomp.CompilerOptions 以及 spock.lang.Specification 。 (我想也许这是关于他们的方式,但这是一个猜测。)






我尝试过的东西



注意:我没有在步骤之间恢复任何进程。 >

0。我的第一个猜猜



我注意到 a howto docs。 codehaus.org 。 IntelliJ找不到 org.gradle.launcher.GradleMain ,所以我修改它使用 GradleLauncher 与以下:

  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

}
}

根据 GradleLauncher的文档



结果: IntelliJ不会编译项目。






1。根据 Peter Niederwieser的回答修正了想法项目&通过插件调试



步骤




  1. 〜#cd / path / to / gradle-js-plugin&& gradle cleanIdea想法

  2. 打开新创建的项目,并尝试使用步骤0中的ScriptRunner进行调试。

结果:项目编译( yay!),但我只能在中点击断点GradleScriptRunner.groovy






2。根据 Peter Niederwieser的回答运行gradle CLI w /特殊选项



1& 2.合并为清楚起见:

 〜#export GRADLE_OPTS = -  Xdebug -Xrunjdwp:transport = dt_socket,server = y,suspend = y,address = 5005
〜#gradle clean assemble
聆听运输dt_socket在地址:5005




  1. 配置IntelliJ连接到此端口并开始调试(见图):

以下.gradle文件配置:



1。仅使用build.gradle



- build.gradle -

 应用插件:'groovy'
应用插件:'java'
应用插件:'idea'
应用插件:'maven'
应用插件:'js '

buildscript {
repositories {
mavenLocal()
mavenCentral()
}

依赖关系{
编译findProject/ path / to / gradle-js-plugin
}
}

存储库{
mavenLocal()
mavenCentral()
}

结果:

  FAILURE:构建失败,异常。 

*其中:
构建文件'/path/to/gradle-js-plugin/src/test/resources/build.gradle'行:13

*出了什么问题:
评估根项目资源时出现问题。
>没有这样的属性:findProject类:org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

* Try:
运行--stacktrace选项来获取堆栈跟踪。使用--info或--debug选项运行以获取更多的日志输出。

BUILD FAILED

总时间:8分钟50.498秒

2。使用build.gradle和settings.gradle



- settings.gradle -

  include/ path / to / gradle-js-plugin

- build.gradle -

 应用插件:'groovy'
应用插件:'java'
应用插件:'idea'
应用插件:'maven'
应用插件:'js'

buildscript {
repositories {
mavenLocal )
mavenCentral()
}
}

存储库{
mavenLocal()
mavenCentral()
}

结果:

  FAILURE:构建失败,异常。 

*其中:
构建文件'/path/to/gradle-js-plugin/src/test/resources/build.gradle'行:5

*出了什么问题:
评估根项目资源时出现问题。
>找不到id'js的插件。

*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多的日志输出。

BUILD FAILED

总时间:13.553秒




我的设置



Gradle



 〜#gradle -v 
----------------------------- -------------------------------
Gradle 1.0
--------- -------------------------------------------------- -

Gradle构建时间:2012年6月12日,星期二12:56:21 UTC
Groovy:1.8.6
Ant:Apache Ant(TM)版本1.8.2 2010年12月20日编译
Ivy:2.2.0
JVM:1.7.0_04(Oracle Corporation 23.0-b21)
操作系统:Linux 3.2.0-2-amd64 amd64



Java



 〜 #java -version 
java版本1.7.0_04
Java(TM)SE运行时环境(build 1.7.0_04-b20)
Java HotSpot(TM)64位服务器虚拟机23.0-b21,混合模式)



IntelliJ



  IntelliJ IDEA终极117.499 w /捆绑Gradle插件



希望



任何可以让我进入插件调试模式的提示。

解决方案

首先,这听起来像你的IDEA Gradle项目有问题。如果您运行 gradlew cleanIdea想法然后从IDEA打开生成的项目(而不是使用JetGradle插件),一切都应该可以。



其次,如果您仍然无法获取GradleMain / GradleLauncher(前一类 存在),另一种方法是将Gradle构建作为外部应用程序进行调试。为此,您需要将 -Xdebug -Xrunjdwp:transport = dt_socket,server = y,suspend = y,address = 5005 添加到 GRADLE_OPTS 环境变量,从命令行运行构建,等待它挂起,然后从IDEA启动一个远程运行配置(具有相应的设置)。在这一点上,调试器应该连接到Gradle进程,你应该启动并运行。


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):

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.

解决方案

First, it sounds like there is a problem with your IDEA Gradle project. If you run gradlew cleanIdea idea and then open the generated project from IDEA (rather than using the JetGradle plugin), all should be fine.

Second, if you still can't get the GradleMain/GradleLauncher (the former class does exist) approach to work, another approach is to debug the Gradle build as an external application. For that you need to add -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 to the GRADLE_OPTS environment variable, run the build from the command line, wait until it suspends, and then start a "Remote" run configuration (with corresponding settings) from IDEA. At that point the debugger should connect to the Gradle process and you should be up and running.

这篇关于使用IntelliJ调试Gradle插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆