我想在IntelliJ中使用交互式调试器。 不幸的是,我无法说服IntelliJ加载和编译插件。但是,我可以gradle clean build
,插件按预期构建并运行其测试。
具体来说,我正在尝试将本地更改调试为gradle-js-plugin ,IntelliJ表示无法找到 com.google.javascript.jscomp.CompilerOptions
以及spock.lang.Specification
。 (我想也许这是关于他们加载的方式,但这是猜测。)
注意:我没有在步骤之间恢复任何进程。
我注意到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's documentation。
结果: IntelliJ无法编译项目。
<小时/>
~# cd /path/to/gradle-js-plugin && gradle cleanIdea idea
结果:项目编译( yay!),但我只能点击GradleScriptRunner.groovy
中的断点。
<小时/>
1&amp; 2.为清晰起见合并:
~# 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
对于此步骤,我尝试了以下.gradle文件配置:
1。仅使用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()
}
结果:
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。同时使用build.gradle和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()
}
结果:
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
<小时/>
~# 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 -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 IDEA Ultimate 117.499 w/ Bundled Gradle plugin
任何让我在插件中进入调试模式的提示。
答案 0 :(得分:28)
我能够使用-Dorg.gradle.debug=true
(找到on gradle forum)调试gradle源(包括插件):
如果有的话,停止守护进程:
./gradlew --stop
运行
./gradlew <task> --no-daemon -Dorg.gradle.debug=true
远程连接到gradle进程(端口5005) - 如果使用IntelliJ IDEA,请参阅上面的OP图像
它现在应该在断点处停止。
顺便说一下,我为gradle源创建了一个单独的IntelliJ IDEA项目。由于我使用gradle包装器,我已经从
中获取了源代码 ~/.gradle/wrapper/dists/gradle-1.11-all/7qd8qq8te5j4f5q9aaei3gh3lj/gradle-1.11/src
在IDEA中我做了File->Import Project
,然后选择了上述路径,然后 - &#34;从现有来源创建项目&#34;。点击下一次(确保我没有包含lib/plugins
目录中的任何jar,因为IDEA会抱怨大多数项目文件已经存在)。
然后我在该IDEA项目中创建了一个远程调试配置,并将其用于调试gradle。
答案 1 :(得分:26)
首先,听起来您的IDEA Gradle项目存在问题。如果你运行gradlew cleanIdea idea
,然后从IDEA打开生成的项目(而不是使用JetGradle插件),一切都应该没问题。
其次,如果仍然无法使GradleMain / GradleLauncher(以前的类确实存在)方法工作,另一种方法是将Gradle构建调试为外部应用程序。为此,您需要将-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
添加到GRADLE_OPTS
环境变量,从命令行运行构建,等待它暂停,然后从IDEA启动“远程”运行配置(具有相应的设置) 。此时,调试器应连接到Gradle进程,您应该已启动并运行。
答案 2 :(得分:14)
IntelliJ IDEA 12.1提供了现成调试gradle任务的功能 - 右键单击JetGradle工具窗口任务列表中的目标任务,然后选择“debug”