Open kwin opened 3 months ago
Is there a guide for moving from org.codehaus.plexus.compiler.AbstractCompiler
to javax.tools.JavaCompiler
.
I was looking through your post and github site but didn't find anything about how the new API works. I tried to have maven-plugin-api
as the only dependency (dropping maven-core
). But I could not see how to do something simple like adding a source folder.
Is this possible via API:
@Mojo(name = "add-groovy-build-paths", defaultPhase = LifecyclePhase.INITIALIZE, requiresProject = true, threadSafe = true)
public class AddGroovySourceFolders extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private org.apache.maven.project.MavenProject project;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
var logger = org.slf4j.LoggerFactory.getLogger(getClass());
logger.info("Adding /src/main/groovy to the list of source folders");
project.addCompileSourceRoot(project.getBasedir() + "/src/main/groovy");
logger.info("Adding /src/test/groovy to the list of test source folders");
project.addTestCompileSourceRoot(project.getBasedir() + "/src/test/groovy");
}
}
Look at https://github.com/eclipse-jdt/eclipse.jdt.core/blob/master/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java how ECJ is implementing that. JSR 199 has additional details: https://jcp.org/en/jsr/detail?id=199
Thanks for the links. In order to test, can I use maven-compiler-plugin
4.0.0-beta-1 or do I need something more recent?
For now you need to build https://github.com/Geomatys/maven-compiler-plugin on your own. The changes are not yet merged upstream.
The upcoming m-compiler-p will get rid of the Plexus Compiler layer but instead directly call javax.tools.JavaCompiler. Further information in https://lists.apache.org/thread/qvrmzmd10plsssrgj4s3f27ytfjxkwfr. In order to use the groovy-eclipse-compiler with the new m-compiler-p it needs to implement
javax.tools.JavaCompiler
instead of Plexus Compiler classes. The latter should be considered deprecated nowadays.This in addition has the advantage of getting rid of a third party abstraction and being usable also outside the m-compiler-p.