redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 440 forks source link

Gradle projects do not build correctly (the bin/ directory again) #2344

Open dsyer opened 2 years ago

dsyer commented 2 years ago

634 is the underlying issue, but that was closed by brushing it under the carpet (IMO it deserves to be fixed). The problem I have is actually worse - the classpath is incomplete because it doesn't contain resources created and/or copied into build/resources/main (for instance) by script targets in the build. It's easy to reproduce the problem - here's an example: https://github.com/scratches/vscode-gradle-nonsense (load it up in VSCode and try and run the tests from the codelens and they fail, even though the build succeeds from command line).

See also https://github.com/microsoft/vscode-java-debug/issues/1127

fbricon commented 1 year ago

If you guys feel strongly about this issue, please vote for https://github.com/gradle/gradle/issues/23032. We can't do anything until this is fixed upstream.

sparrowt commented 1 year ago

Looks like the linked issue has now been resolved - does this unblock things now? Many thanks.

dsyer commented 1 year ago

Is there any way to try it? The current "pre-release" version of VSCode extension doesn't fix the problem.

snjeza commented 1 year ago

@dsyer you may want to take a look at https://github.com/redhat-developer/vscode-java/issues/1615#issuecomment-1512864529

dsyer commented 1 year ago

I tried that. It didn’t solve anything for me. Maybe I missed a step. Please feel free to add a PR to my project.

CsCherrYY commented 1 year ago

https://github.com/redhat-developer/vscode-java/issues/1615#issuecomment-1512864529 can change the output folder from bin to build, but it can't solve the issue mentioned in https://github.com/eclipse/buildship/issues/1236

snjeza commented 1 year ago

@dsyer could you try the following patch:

diff --git a/build.gradle b/build.gradle
index 478a825..0fc7bb6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,6 +2,7 @@ plugins {
        id 'org.springframework.boot' version '2.6.4'
        id 'io.spring.dependency-management' version '1.0.11.RELEASE'
        id 'java'
+       id 'eclipse'
 }

 group = 'com.example'
@@ -36,4 +37,11 @@ task metaProperties() {
         props.setProperty("version", "${project.version}")
         props.store(output.newOutputStream(), null)
     }
-}
\ No newline at end of file
+}
+
+eclipse {
+    synchronizationTasks processResources
+    classpath {
+        defaultOutputDir = file('build/resources/main')
+    }
+}
dsyer commented 1 year ago

This patch work for me, thank you. I'm not sure if it breaks anything else, since it seems to change the default settings of the eclipse plugin. I'm also not sure why it's different to #1615.

xerx593 commented 1 year ago

i also tried (with today's setup) this, @dsyer : At no avail/works like charm! (Though it took some time unitl "gradle" and "java" came up...but once the "build folders" (as the "play buttons" on tests) are available:

image