groovy-eclipse icon indicating copy to clipboard operation
groovy-eclipse copied to clipboard

groovy-eclipse-compiler should implement javax.tools.JavaCompiler

Open kwin opened this issue 1 year ago • 5 comments

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.

kwin avatar Aug 07 '24 07:08 kwin

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");
    }
}

eric-milles avatar Aug 09 '24 15:08 eric-milles

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

kwin avatar Aug 10 '24 10:08 kwin

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?

eric-milles avatar Aug 10 '24 13:08 eric-milles

For now you need to build https://github.com/Geomatys/maven-compiler-plugin on your own. The changes are not yet merged upstream.

kwin avatar Aug 10 '24 14:08 kwin

4.0.0-beta-2 contains the relevant changes.

kwin avatar Mar 03 '25 07:03 kwin