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

Could really use an example of how to transform a dependency needed at compile time #669

Open
davidmichaelkarr opened this issue Oct 4, 2024 · 2 comments

Comments

@davidmichaelkarr
Copy link

We are attempting to use the Transformer maven plugin for a use case that I've never seen described, but which I would think would be possible.

We have a bunch of SpringBoot applications that depend on artifacts that use the "javax" packages in their source code. We now require they use the "jakarta" packages. However, we require these artifacts to be used at compile time, not just runtime. I've seen a number of examples using the transformer where it will package up the transformed jars, but never a case where it uses the transformed jars at compile time.

@bjhargrave
Copy link
Member

You could use the IT test in https://github.com/eclipse/transformer/blob/main/maven-plugins/transformer-maven-plugin/src/it/simple-jar/pom.xml as an example of making a new artifact by transforming an existing artifact. This new artifact can then be a compile time dependency of another project in the maven build.

@davidmichaelkarr
Copy link
Author

I think the key point here is that with Maven, there is a big difference in thinking something could be done and actually doing it. I believe I've managed to put something together that demonstrates this, but I discovered afterwards that there were some other issues with my test case unrelated to this, so I'm not certain yet whether it fully deals with the problem. Some other people will have to deal with those questions on Monday.

The "trick" to get it to fully work is to use the "jar" goal and then use the "maven-antrun-plugin" to extract the contents of all the transformed jars into "target/classes", and do this in the "prepare" phase. I'm not sure if I can find this documented anywhere, but it appears that the maven-compiler-plugin will use target/classes not just as the destination for compiled classes, but also additional classpath for classes being compiled. These classes being present in target/classes will also take precedence over the same FQCNs the compiler finds in the untransformed versions of the dependency artifacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants