VP.
VP.

Reputation: 16775

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. But now I am trying to debug my java project in IDEA with Gradle 1.11. 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:

  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

But with gradle project idea not uses gradle structure.

How can I debug my java project right from IDEA IDE with gradle?

P.S. 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. Hope it is clear what I want to do.

Upvotes: 5

Views: 5263

Answers (1)

VP.
VP.

Reputation: 16775

Problem was solved by using application plugin of gradle.

In build.gradle we need to apply this plugin by adding line:

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.

But if you have a distribution plugin applied to in your project they will conflict. You need to delete the line of applying distribution plugin and any section of this plugin like distributions {...

Application plugin information

Upvotes: 5

Related Questions