vscode java doesn't work with multi-project layout gradle project - java

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.

Related

remove and add project dependencies with gradle/intellij

I am a Java newbie here. I am thinking of a way to remove all the project dependencies.
For example in nodejs, we can simply remove the node_module folder and then do an npm install.
I am using Gradle and IntelliJ IDEA
How can I do the following:
Remove the dependencies from the project
Re-add the dependency again
Lastly where do I see all the dependencies along with its version number in IntelliJ
To remove dependencies from the project, simply go to your
build.gradle file and remove all the lines containing
"implementation", "complie" or anything similar.
However if you just want to remove them from cache and redownload
them simply enter this command in the terminal:
gradle clean build
or in the gradle menu which you can find in the IntelliJ Sidebar
press "Reload all gradle projects"
To see the version of the dependencies you can either use
"Dependencies" new feature of IntelliJ, or find them in the
build.gradle file.
more info here
You can Remove the already installed dependencies by using clean command
gradle clean build
The clean task is defined by the java plugin and it simply removes the buildDir folder, thus cleaning everything including leftovers from previous builds which are no longer relevant. Not doing so may result in an unclean build which may be broken due to build artifacts produced by previous builds.
As an example assume that your build contains several tests that were failed and you decided that these are obsolete thus needs to be removed. Without cleaning the test results (using cleanTest task) or the build entirely (by running the clean task) you'll get stuck with the failed tests results which will cause your build to fail. Similar side effects can happen also with resources/classes removed from the sources but remained in the build folder that was not cleaned.
This will remove the old dependencies and build them back together once again .
and about the dependencies , to check Without modules:
gradle dependencies
For android :
gradle app:dependencies
Note: Replace app with the project module name
Here is a possible solution , Another one would be to create a gradle task inside build.gradle:
subprojects {
task listAllDependencies(type: DependencyReportTask) {}
}
Then call the task with
gradle listAllDependencies
and one final simple solution is using Project report plugin
Add this to your build.gradle
apply plugin: 'project-report'
And Then generate a HTML report using:
gradle htmlDependencyReport
And here is IntelliJ IDEA specific way .
Hope i helped .

How to Revert Nested Project in Eclipse [duplicate]

When I create a Gradle project in Eclipse the result is a nested project with a -lib folder created automatically. Any ideas on why this is being created?
I tested this on Eclipse 2021-03 using the latest gradle version 7.0-rc-1 and reproduced your issue where a nested project with a lib subproject was created. I then made a new Eclipse project specifying Gradle version 6.6 to be used and the resulting project was not nested. I suggest trying Gradle 6.6 and seeing if you get the same behavior I got. This might fix your project.
Also try running the gradle init command from the command line and see what project structure you get there. I tested this on my PC where I have gradle 5.6 as the default version and got a non nested structure. You can of course always manually modify your gradle project in a few minutes to not be nested.

Intellij IDEA and Gradle projects

I have a new project. Should I place apply plugin: 'idea' in build.gradle and run $ gradle idea? Or should I import the gradle project directly into IntelliJ IDEA 14.1? Which one will allow me to add dependencies to build.gradle and have IDEA automatically download & know about them?
With Intellij 14 you can just open the the build.gradle file using Intellij's File --> Open. this will import the gradle project, including all dependencies.
After you change something in the build.gradle file, you can click on "refresh all gradle projects" at the top of the gradle tool window.
You may also mark "use auto-import" under the Build Tools/Gradle tab in Settings. This will resolve all changes made to the gradle project automatically every time you refresh your project.
The idea plugin is the old method of importing a gradle project into Intellij.
With the newer versions of Intellij, it has become redundant.
From my experience using the idea plugin does not always work correctly in IntelliJ and actually IntelliJ documentation guidelines are to simply import build.gradle file.
Also, Peter Niederwieser who is a Principal Software Engineer at Gradleware answered a similar question ~2 years ago mentioning the following:
If you use Gradle's idea task to generate project files, this is normal, as there is no way to tell IDEA what the class path of the build script itself is. If you instead use IDEA's Gradle integration ("Import from Gradle model"), this problem doesn't exist.
Bottom line, your safer way to go would be importing gradle project directly from IntelliJ.
You can create a new Gradle Project in IntelliJ, and it will handle all of the dependencies and integrate well with Gradle. You can see here for more info and specifics.

Eclipse build errors when using Gradle or Maven?

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.

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:
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

Categories

Resources