spring-projects / spring-petclinic

A sample Spring-based application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicate results when finding owners

CsCherrYY opened this issue · comments

Issue

This issue can be reproduced in both VS Code and eclipse.

Steps to reproduce:

  1. Given the newest spring-petclinic (0962ed7 for now)
  2. run ./gradlew build in the project folder
  3. Open the project in either VS Code or eclipse, import as Gradle project, and wait for the project imported
  4. Run the spring-petclinic application, and open the browser
  5. Go to "Find Owners" page, input "C" and try to find Owner
  6. We can see the result:
    image

Finding

  1. We can find there are several unexpected source folders in the project dependencies, view the project dependencies:
  • in VS Code, open "Java Projects" view, expand "Project and External Dependencies" node
  • in eclipse, open "Package Explorer" view, expand "Project and External Dependencies" node
  1. The output folder of main source set can be found in the node:
    image

I can confirm before commit 0962ed7 everything works well. The root cause is that Gradle plugin org.graalvm.buildtools.native, which will introduce the spring aot plugin org.springframework.boot.aot that causes this issue. After disabling that plugin, the application works well.

if you can't reproduce this issue, please run ./gradlew build and clean workspace, see step 2 above.

It seems to be an issue with vscode/buildship not the PetClinic? Is there anything we can do here?

I'm not sure I follow that reasoning. I also can't reproduce the problem - maybe you have a different version of the VSCode plugins (I have the "Extension Pack for Java" v0.25.10)? I can see that there are duplicate .class files in the runtime classpath, but I don't understand how the extra database records get created because the .sql scripts are resources (not classes) and they are not duplicated in the runtime classpath.

@dsyer could you run ./gradlew build and clean workspace after then?

Nevermind, I can reproduce it now. I don't think I was using Gradle in VSCode before. We should open an issue in Spring Boot. Do you want to do that?

Do you want to do that?

Can we just transfer this issue there and change the title? If that's not suitable, I can create a new issue there.

The Boot team say it's a problem in Buildship, so you should open the issue there (and this one can't be transferred). I have a small reproducer if you want to link to that, or copy it: https://github.com/scratches/gradle-aot.

@dsyer Thanks a lot for the project, that's cool! issue created: eclipse/buildship#1236

commented

@dsyer You can try the following patch

diff --git a/build.gradle b/build.gradle
index d0a34bf..aeee005 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,6 +3,7 @@ plugins {
   id 'org.springframework.boot' version '3.0.4'
   id 'io.spring.dependency-management' version '1.1.0'
   id 'org.graalvm.buildtools.native' version '0.9.20'
+  id 'eclipse'
 }
 
 apply plugin: 'java'
@@ -40,3 +41,18 @@ dependencies {
 tasks.named('test') {
   useJUnitPlatform()
 }
+
+eclipse {
+  classpath {
+    defaultOutputDir = file('build-default')
+    file {
+        whenMerged {
+            cp -> cp.getEntries().forEach{
+                cpEntry -> if(cpEntry.path=='src/main/resources') {
+                    cpEntry.output = 'build/resources/main'
+                }
+            }
+        }
+    }
+  }
+}