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:
Set debug configurations
Run it under debug
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.
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
Related
java vscode doesn't work well with multi-project layout gradle project. I can simply reproduce this with the sample project generated by gradle init.
The error msg looks like some building task dependency issues: Cannot use Gradle object after build has finished
I've described the issue here https://github.com/redhat-developer/vscode-java/issues/1984
Just want see if anyone have met such issue before and any idea for a workaround?
I create a demo gradle project by Spring Initializr Java Support, with build.gradle and settings.gradle generated automatically, so when i run gradle init, it would throw > Task :init SKIPPED because settings file and build file already existed.
After i delete them manually, gradle init could be executed successfully and re-generate build.gradle and settings.gradle:
I've noticed the comment below your github issue:
This issue seems similar to another one I'm seeing with eclipse
buildship, so most likely it's an issue happening in latest gradle
version
And I'm using Gradle 7.0.2, there's no error shown. You may have a try.
I found gradle tasks shown below in my Eclipse Java Spring project:
application
bootRun
build
assemble
bootBuildImage
...
build setup
documentation
help
ide
verification
What these tasks are coming from? Is it part of Gradle or Spring?
(1) You ask
What these tasks are coming from?
Gradle task come from 2 area: by Gradle itself and by Gradle plug-ins.
For example, at folder where has file build.gradle , (1a) when you run command
gradle bootRun
Spring Boot application when run, it usually run and return result at http://localhost:8080 (default). gradle bootRun run success by an plugin called Spring-boot-gradle-plugin declared inside build.gradle .
(1b) When you run
gradle wrapper
your project will add some folder and files, make your source code become portable, no need install Gradle at local PC when you share for your colleagues. gradle wrapper come from Gradle itself, not from third-party one.
(2) You ask
Is it part of Gradle or Spring?
(1b) from Gradle itself, (1a) is a plug-in made by Spring team.
Reference: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin
They look to be gradle as assemble, build, buildDependencies are all standard irrespective of what you are building.
I'm trying to start some work on a Gradle project, but I get a strange error when attempting to build the project on my machine. Currently, we have a Gradle project that builds successfully for all other members of my team, all they need to do is clone the project and it builds without any problems. For myself, that isn't the case.
If I execute the gradle wrapper manually from the terminal:
./gradlew build
the project builds without any errors, but the Gradle synchronisation fails when importing the project into an IDE, giving the following error:
* What went wrong:
Could not resolve all dependencies for configuration ':billing-
provisioning-consumer-finance-details:compile'
I assume that it can't be a problem with the project structure, nor anything wrong with the build.gradle, since it builds without error on other machines.
So far I've tried:
Re-cloning the project (several times)
Clearing the gradle cache at ~/.gradle/caches
Clearing ~/.m2/repositories
Building the project in another IDE (Eclipse), which still gives the same error.
You can follow these steps :
Download Gradle from Gradle
Create or Export GRADLE_HOME as environment variable.Ex: E:\SoftwareRepo\building tools\gradle-4.4.1
Add to Path or Export Path Variable PATH=[YOUR GRADLE_HOME/bin] . ex. E:\SoftwareRepo\building tools\gradle-4.4.1\bin
Open cmd or terminal anywhere in your PC and run gradle --v . If gradle install successfully it will show installed gradle info.
Clone your gradle project
Go to project root directory. Open terminal and run gradle clean build
If there is still error then it will be probably your project is not correctly configured.
If you tried with intelij idea then you need to try this
File->Open. then select your source folder.
then a popup will come select local destribution gradle
IntelliJ IDEA 2016.3 add the ability to delegate build/run to Gradle.
It's clear that when the delegate option is on Gradle is doing everything.
My question is what exactly IntelliJ is doing when this option is off?
I'm asking this because I have custom code inside my Gradle files and it does not seems like this code is executed when building in IntelliJ. When I run gradlew build everything works just fine.
IntelliJ has its own build system, called JPS, which uses the IntelliJ IDEA project and .iml files as the project model. When you're using IntelliJ IDEA's default build system to build the project, it does not execute any code in Maven or Gradle files; it uses its own logic, which can only be extended by writing plugins to JPS.
When using a build manager like Gradle or Maven, my dependencies are being managed correctly, however the Eclipse IDE is unaware of the resolved dependencies so it will still show errors and I cannot build through Eclipse, I have to run a 'build' command through the build manager.
How do you get Eclipse to be aware of the resolved dependencies taken care of by a build manager and running the app through the IDE?
You can generate Eclipse metadata using eclipse plugin distribute with Gradle - http://www.gradle.org/docs/current/userguide/eclipse_plugin.html - this will set up the project with its classpath.
Or install Gradle plugin for Eclipse developed by Pivotal folks.
The question is vague. Using m2e or Gradle plugin for Eclipse developed by Pivotal can lead you to different errors. You should ask exact question, sharing error that you got here on stackoverflow.