简体   繁体   English

IntelliJ IDEA中的Gradle Java调试项目

[英]Gradle Java debugging project in IntelliJ IDEA

I've used previously maven 3 and it was easy to run anything from IntelliJ IDEA 13 , be at main classes or tests - it worked through maven settings. 我已经使用过以前的maven 3 ,很容易从IntelliJ IDEA 13运行任何东西,在主要类或测试 - 它通过maven设置工作。 But now I am trying to debug my java project in IDEA with Gradle 1.11 . 但现在我正在尝试使用Gradle 1.11在IDEA中调试我的java项目。 The problem is that idea now creates /out/* directory and trying to run my classes from there instead of using gradle settings and build setups - I mean, with maven I could debug my java project by this: 问题是想法现在创建/ out / *目录并尝试从那里运行我的类而不是使用gradle设置和构建设置 - 我的意思是,使用maven我可以通过这个来调试我的java项目:

  1. Set debug configurations 设置调试配置
  2. Run it under debug 在调试下运行它
  3. 2 step will call maven install and will run my java project from target/classes/ directory 2步将调用maven install并将从target/classes/目录运行我的java项目

But with gradle project idea not uses gradle structure. 但是gradle项目的想法不使用gradle结构。

How can I debug my java project right from IDEA IDE with gradle? 如何使用gradle从IDEA IDE调试我的java项目?

PS I can run gradle test under debug in IDEA and it works perfectly, but I need something like gradle debug or gradle run to set breakpoint in IDE, run my Main class and launch my java application through IDE. PS我可以在IDEA的调试下运行gradle test ,它运行得很好,但我需要像gradle debuggradle run这样在IDE中设置断点,运行我的Main类并通过IDE启动我的java应用程序。 Hope it is clear what I want to do. 希望很清楚我想做什么。

Problem was solved by using application plugin of gradle. 通过使用gradle的application plugin解决了问题。

In build.gradle we need to apply this plugin by adding line: build.gradle我们需要通过添加行来应用此插件:

apply plugin: 'application'

And setup main class name: 并设置主类名称:

mainClassName = "Main"

(Main is my main class). (主要是我的主要课程)。

After that in IDEA we need to create configuration to run gradle's run -task and run it under debug. 在IDEA之后,我们需要创建配置来运行gradle的run -task并在debug下运行它。

But if you have a distribution plugin applied to in your project they will conflict. 但是如果您在项目中应用了distribution插件,则会发生冲突。 You need to delete the line of applying distribution plugin and any section of this plugin like distributions {... 您需要删除应用distribution插件的行以及此插件的任何部分,如distributions {...

Application plugin information 应用程序插件信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM