Caesar
Caesar

Reputation: 8544

maven-compiler-plugin: add extra dependency for incremental build

I want to construct a java class file with a class with a long, multi-line string constant. (The usual way of putting the string into a separate file and load it from the same JAR as the class is not an option. There won't be a JAR, only that class file.) Originally, I was using the multiline-string annotation-processor, it allows to place the string content in a doc comment:

/**
 * This will be the actual
 * content of the string
**/
@Multiline static final String foo = "this literal is ignored";

Here I mistakenly thought: "oh, comments are inconvenient, why not change multiline-string to load the content from an external file?" It turns out that this works, but maven (which I'm using for building), does of course not understand that the class file needs to be recompiled if the file read by the annotation processor is changed.

Approaches:

What I'd really like to do is to add the path of the embedded file to maven's list of "if this file changes, recompile that file". Is that possible, or is there another, elegant way of solving this?

Upvotes: 4

Views: 583

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42541

Maybe this is not a full answer, but just my thoughts on the above:

Annotation processors in java usually are not intended for changing the existing classes.

Yes, there is Lombok, that kind of breaks this assumption, but the price is using some internal compiler internal APIs and "Manually" compiling the modified AST:

This is also written in this tutorial for example.

Usually annotation processors can create some descriptors, like JSON or files, or, alternatively new Java sources, but they never (again with the exception of lombok) modify the existing sources.

If I've got you correctly, you wrote your own annotation processor for multi-line handling like the one that you've provided in the first link, but this kind of incompatible with the idea of annotation processors, so I doubt maven can help you out here.

Upvotes: 1

Related Questions