Let's say that I have a designated class that contains only static fields and methods.
class Utils {
public static final String FOO = "foo";
public static void bar() {
System.out.println("Something");
}
}
Now, here's a class that references some methods and constants from it:
class Main {
public static void main(String[] args) {
String s = Utils.FOO;
Utils.bar();
}
}
How can I make Maven copy those referenced members and produce a "fat" bytecode class that wouldn't rely on the original class that contained them? Those changes would only be applied right before compilation and wouldn't be reflected the source code itself, but they would essentially look like:
class Main {
public static final String FOO = "foo";
static void bar() {
System.out.println("Something");
}
public static void main(String[] args) {
String s = FOO;
bar();
}
}
EDIT: If making a custom Maven plugin is the only solution, then I would appreciate some examples of preprocessing Java code just before it gets passed to the compiler.
EDIT2: I solved this problem by making two custom Python scripts and attaching them to the lifecycle with exec-maven-plugin. The first one copies static fields and methods from designated package and pastes them where they're referenced, the second one reverts those changes right after the build is done.