Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 766
Victor Polevoy Avatar asked Feb 28 '14 05:02

Victor Polevoy


People also ask

How do I debug a Gradle project?

To do that, just pick the Gradle Remote Debug configuration and then click the Debug icon on the project to be debugged. For more info, you can read the Gradle documentation. Follow us for more productivity tools & ideas for Android, Kotlin & Gradle projects.

How do I run a Java Gradle project in IntelliJ?

In the Gradle tool window, open the project's node, then the Tasks node and double-click the build task to run it. IntelliJ IDEA creates the build directory that contains our JAR file. You can run the created JAR file in the command line with java -jar command. Check the Run tool window for the results.

How do I open a project as Gradle project in IntelliJ?

Open your project in IntelliJ IDEA. In the Project tool window, right-click the name of your project and select New | File. In the dialog that opens enter build. gradle and click OK.


1 Answers

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

like image 189
Victor Polevoy Avatar answered Oct 07 '22 01:10

Victor Polevoy