Code generating annotation processors #2242
-
|
Hi, I'm trying to use the record-builder package in my I read that For example, given the following script, //DEPS io.soabase.record-builder:record-builder-processor:49
//DEPS io.soabase.record-builder:record-builder-core:49
import io.soabase.recordbuilder.core.RecordBuilder;
@RecordBuilder
record ReleaseInfo(
Integer nativeVersion,
Integer apiVersion,
Set<String> artifacts,
String command
) implements ReleaseInfoBuilder.With {
}
void main() {
var r = new ReleaseInfo(1, 2, Set.of(), "").withCommand("testCommand");
IO.println(r);
}
Is there anything else I need to do / missing to get this working? I saw #1650 but was unsure what the resolution was there. Cheers! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
|
I'm not at laptop atm but my first guess is that that annotation processor used are struggling with default unnamed package. Try add a package statement on top and see if it makes a difference. |
Beta Was this translation helpful? Give feedback.
-
|
sorry for the delay in looking into this - but now I've looked and I come with good and some bad or weird news ;) The good - annotation processors does work with JBang - see https://gist.github.com/maxandersen/0a82685f7182ba8be3edc54132bc2042 for some examples I made to test this. The bad/weird news: the naked main in java 25 triggers something that fail which I haven't figured out yet why I get the errors. In gist above I made one with non-Java 25 syntax. Also see the readme for usefull flags to use like: JAVA_TOOL_OPTIONS=-Djbang.build.keepclasses=true` to keep the generated classes. Use So add ...easier to debug - and definitely realizing we can/should make this simpler/better documented :) brb - going to fight with java 25 :) |
Beta Was this translation helpful? Give feedback.
-
|
ok figured it out (thanks to @quintesse pointing out the obvious :) In Java 23+ you need to explicitly enable annotation processors, simplest is to put But that still does not work for soabase because they don't support default package - and to use naked mains you can't use packages. I've created https://gist.github.com/maxandersen/1e1cc817125ce3abd09525133398d59b with examples of what works and what does not work. So in conclusion:
|
Beta Was this translation helpful? Give feedback.
ok figured it out (thanks to @quintesse pointing out the obvious :)
In Java 23+ you need to explicitly enable annotation processors, simplest is to put
//JAVAC_OPTIONS -proc:fullwhich "restores" the pre-Java 23 behavor.But that still does not work for soabase because they don't support default package - and to use naked mains you can't use packages.
I've created https://gist.github.com/maxandersen/1e1cc817125ce3abd09525133398d59b with examples of what works and what does not work.
So in conclusion: