Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FindDeclaredProcsTask use the JDK of the configured Java toolchain to load classes #1167

Open
jjohannes opened this issue Apr 15, 2024 · 1 comment
Assignees
Labels
bug Something isn't working toolchain:java
Milestone

Comments

@jjohannes
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

Right now, if you configure a toolchain with a Java version (e.g. 21) that is higher than the version you run Gradle with (e.g. 17) you may get the following exception for Annotation Processor class files:

Caused by: java.lang.UnsupportedClassVersionError: ...AnnotationProcessor has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
        at com.autonomousapps.tasks.FirstClassLoader.loadClass(FindDeclaredProcsTask.kt:390)
        at com.autonomousapps.tasks.FindDeclaredProcsTask.procFor(FindDeclaredProcsTask.kt:129)
        at com.autonomousapps.tasks.FindDeclaredProcsTask.procs(FindDeclaredProcsTask.kt:116)
        at com.autonomousapps.tasks.FindDeclaredProcsTask.action(FindDeclaredProcsTask.kt:93)

https://scans.gradle.com/s/bcxd6sczjyfhk/failure#1

Describe the solution you'd like

The FindDeclaredProcsTask task works in the described setup and does not throw.

Describe alternatives you've considered

The solution is to run the build itself with a JDK that corresponds to the configured toolchain or is newer.

Additional context

  • Maybe this can be solved by using a worker action that runs in process isolation (?)
  • Or could the task be implemented without classloading (?)

Do you think this can be solved somehow @autonomousapps? If yes, I can attempt to provide a fix.

@jjohannes jjohannes changed the title Make FindDeclaredProcsTask uses the JDK of the configured Java toolchain to load classes Make FindDeclaredProcsTask use the JDK of the configured Java toolchain to load classes Apr 15, 2024
@autonomousapps autonomousapps added bug Something isn't working toolchain:java labels Apr 15, 2024
@autonomousapps autonomousapps added this to the next milestone Apr 15, 2024
@autonomousapps
Copy link
Owner

I'm open to any solution to this problem that works and is maintainable. In the past, I considered trying to use a worker action with process isolation; actually I vaguely recall trying this and running into a major issue that felt like a bug in that API.

The reason I'm using a custom classloader here is that i need to "ask" the annotation processor which types it supports.

I think we have pretty good regression tests around this subject, so if you have time, feel free to experiment and see what solves your problem while also keeping the existing tests passing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working toolchain:java
Projects
None yet
Development

No branches or pull requests

2 participants