redhat-developer / redhat-developer/vscode-java

Gradle Generated Sources from Annotation Processor not picked up correctly by intellisense nor will work with Run/Debug

Đang mở
#2,981 0 bình luận 10 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
TypeScript
Star
2.3k
Fork
546
Merge trung bình
20 giờ 1 phút
Pull request đã merge (30 ngày)
11

Mô tả

Problem:
Unable to use annotation processor from Gradle and have intellisense or the run/debug menu work. Results in not found or package path issues.

  1. Using gradle build task, it compiles fine without issue
  2. Using gradle task from "fabric -> runClient" works fine without issue
  3. Using fabric -> configureClientLaunch to create the vscode launch.json does not allow me to use the Run and Debug if I am using annotation processor. Without it, it will work fine.
  4. Lombok works without issue
  5. Intellisense in source files that use the generated source will result in "The import net.glass.settings.GlassConfig cannot be resolved"
  6. Intellisense in generated files, when seen, will result in The declared package "net.glass.settings" does not match the expected package ""

I have seen some previous closed issues on this on this "eclipse jdt" repo and here, but I haven't had any success. I have yet to be able to get this to work without resorting to manually moving files around. Note that I do not know much about gradle nor do I know what eclipse is other than the IDE.

#2793 Support Gradle Annotation Processing
https://github.com/eclipse/eclipse.jdt.ls/pull/2319

I have also somewhat seen this mentioned on the Gradle Plugin page, but there are no real instructions or examples on HOW to change the source sets to make vscode happy, which doesn't even seem to be possible with version 8 of gradle.

See Class References section
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-gradle

Environment
  • Operating System: macOS Ventura 13.2.1 (M1 mac)
  • JDK version: 17.0.2
  • Visual Studio Code version: 1.76.0 (Universal)
  • Java extension version: v1.15.0
  • Gradle Version: Tried both the latest version of 7 and 8
  • Gradle Extension Version: v3.12.6
Steps To Reproduce
  1. Include an annotation processor under dependencies
  2. Gradle build task to create generated source file
  3. vscode will complain about missing class

My repo is here:
https://github.com/alison-gravley/Glass

Not sure if these are the right log files. This was under the F1 -> Toggle Developer Tools -> Console tab

ERR ENOENT: no such file or directory, open '/Users/alison/Library/Application Support/Code/User/workspaceStorage/0d20f7af9fd0c96c108f44b4cb73ffde/redhat.java/jdt_ws/.metadata/.log': Error: ENOENT: no such file or directory, open '/Users/alison/Library/Application Support/Code/User/workspaceStorage/0d20f7af9fd0c96c108f44b4cb73ffde/redhat.java/jdt_ws/.metadata/.log'

unamed.log
client_2023_03_04.log
client_2023_03_05.log

Current Result

Intellisense does not see the generated source files and they show up as errors
Run & Debug views these as compilation errors and will not run

Things I have tried

I have tried several build.gradle changes that result in the sources sometimes being seen, but never interpreted correctly. I have reloaded the project from Gradle and deleted the workspace from Java Project on every change.

I have tried turning "Java › Import › Gradle

› Annotation Processing: Enabled" both on and off. More info below on that.

build.gradle
Solution 1: Eclipse???

Eclipse example I found. I have no idea what eclipse is other than the IDE, so I am not sure what all of these eclipse references are about. I do not have the eclipse IDE.

plugins {
	id 'fabric-loom' version '1.0-SNAPSHOT'
	id 'maven-publish'
	id 'io.freefair.lombok' version '6.6.1'
	id 'java'
    id 'eclipse'
}
...
dependencies {
...
    annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}")
...
}
...
eclipse {
    classpath {
        containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
        file.whenMerged { cp ->
            def entries = cp.entries;
            def src = new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/generated/sources/annotationProcessor/java/main', null)
            entries.add(src)
        } 
    }
}
Solution 2: Various versions of adding the directory to source sets, but they cause warnings with Gradle and as of version 8 I cannot do this method at all without the below error.

Task ':sourcesJar' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.

plugins {
	id 'fabric-loom' version '1.0-SNAPSHOT'
	id 'maven-publish'
	id 'io.freefair.lombok' version '6.6.1'
	id 'java'
}
...
dependencies {
...
    annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}")
...
}
...
sourceSets {
    test {
        runtimeClasspath += main.runtimeClasspath
        compileClasspath += main.compileClasspath
    }
    //With version 8 of gradle, this is no longer allowed and will not compile
    main {
        java {
            srcDir 'build/generated/sources/annotationProcessor/java/main'
        }
    }
}
Enabling Java › Import › Gradle › Annotation Processing: Enabled

Note: Eclipse and source sets items removed at this point

This adds a "bin/generated-sources/annotations" folder in addition to the ones that gradle creates within their build directory. This option gets me a step further, but I run into package path issues: The declared package "net.glass.settings" does not match the expected package ""

The only way I found to get this to work was to manually add the package path to the annotations folder and move the generated source file to there. This at least allows the intellisense AND Run & Debug to work as expected.

The only issue with this is eventually the file gets regenerated and I end up with 2 copies. Usually when I have to eventually "Clean Workspace", because something in the cache gets corrupted during a build or I change build.gradle and things get in a bad state. This is also bad as anytime I make a change to the class, I will have to manually fix it again.

In my specific example, I manually created the net.glass.settings folders so the package error would go away.
bin/generated-sources/annotations/net/glass/settings/GlassConfig.java

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với kho lưu trữ Glass đã được báo cáo và build.gradle của nó, sau đó kiểm tra entry point configureClientLaunch và các log đính kèm trong khi tái hiện các lỗi khi import mã nguồn được sinh và khi Run/Debug. So sánh các đường dẫn mã nguồn của bộ xử lý annotation của Gradle với cấu hình dự án Java; hoàn tất khi các lớp được sinh được phân giải trong IntelliSense và Run/Debug mà không cần di chuyển tệp thủ công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, vscode
Lĩnh vực
developer-experience, devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.