You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Martin Desruisseaux <ma...@geomatys.com> on 2024/07/22 16:41:10 UTC
Status of new compiler plugin for Maven 4
Hello all
The work on a new maven-compiler-plugin [1] for Maven 4 has reached the
following state:
* All existing JUnit tests pass
* Integration tests do not yet pass (I'm working on that)
* Plexus compiler dependency completely removed (replaced by javax.tools)
My current issue is that dependencies of type "test-jar" are lost. I'm
not sure if I'm doing something wrong or if this is an issue with Maven
core. The code looks like that:
DependencyResolver resolver = session.getService(DependencyResolver.class);
DependencyResolverResult dependencies
.session(session)
.project(project)
.pathScope(PathScope.TEST_COMPILE)
.build());
In a step-by-step debugging, I see that
org.apache.maven.internal.impl.AbstractSession.toDependency(…) is
invoked for transforming a dependency from Maven model to Aether model
as below (line 274):
new org.eclipse.aether.artifact.DefaultArtifact(
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getClassifier(),
dependency.getType().getExtension(),
dependency.getVersion().toString(),
null)
I did not saw the "test-jar" anywhere in the copied object, or did I
missed something? Or is this code supposed to generate automatically a
"tests" classifier when the type is "type-jar"?
Generally speaking, having coexisting models such as Maven and Eclipse
Aether with conversions between those models makes more difficult to
follow what is happening inside Maven core, and is a risk of data lost.
Don't we have an overlap between the following interfaces, and if yes,
should we try to reduce the overlap?
* org.eclipse.aether.graph.Dependency
* org.apache.maven.api.Dependency
* org.apache.maven.api.DependencyCoordinate
Thanks,
Martin
[1]https://github.com/Geomatys/maven-compiler-plugin
Re: Status of new compiler plugin for Maven 4
Posted by Martin Desruisseaux <ma...@geomatys.com>.
I created a pull request for Maven core which fixes the issue that the
new maven-compiler-plugin was facing (the confusion between "jar" and
"test-jar"). With this fix, I'm starting to be able to compile the
projects in my company with the new compiler.
https://github.com/apache/maven/pull/1621
However, for future Maven developments, I have a wish. Pretty much every
classes in the "org.apache.maven.internal.impl" package are public.
Would it be possible to reduce visibility as much as possible? A drastic
approach could be to make every classes package-private, then turn back
to public only the classes that appear necessary for compilation or
execution. The reason is because there is a lot of room for improvements
in Maven, but with everything public, I do not really dare to propose
too much refactoring. The pull request in this email contains an
opportunistic refactoring for reducing code duplication. But I do not
know if by doing so, I'm breaking code in other modules that may be
using the implementation classes directly.
This with about reducing "org.apache.maven.internal.impl" visibility
applies also to every implementation packages in Maven.
Martin
Re: Status of new compiler plugin for Maven 4
Posted by Martin Desruisseaux <ma...@geomatys.com>.
Le 2024-07-23 à 01 h 15, Guillaume Nodet a écrit :
> Awesome work ! Does ECJ implement javax.tools API too ?
Thanks! I did not tested the Eclipse compiler, but from my search on
internet, I got the impression that yes it implements the javax.tools
API too. If not the case, it should be possible to create a wrapper.
> The org.eclipse.aether.graph.Dependency objects should not be used and
> will not even be exposed once/if [1] is merged. One of the goals of
> the Maven 4 API was to hide the resolver completely, so I'm not sure
> how to not wrap those. But if you have some suggestions...
>
Maybe, after Aether became completely hidden from users point of view,
copy the code to the Maven core module (as internal packages), then
delete Aether interfaces one-by-one by replacing them by their Maven API
equivalent? But we can keep that work for later.
> For this particular point, there are really only two implementations
> of org.apache.maven.api.DependencyCoordinate which are
> org.apache.maven.internal.impl.DefaultDependencyCoordinate and the
> anonymous class defined in
> org.apache.maven.internal.impl.DefaultProject, which wraps a
> org.apache.maven.api.model.Dependency. Both should have the getType()
> return a correct value, so passing null to the
> org.eclipse.aether.artifact.DefaultArtifact constructor [2] definitely
> looks like a bug.
>
Actually `getType()` returns the correct value, but that value is not
given to the Aether object. It is decomposed in two strings: the
classifier and the file extension. The file extension is "jar", which is
maybe the reason why "test-jar" become confused as "jar" type, and the
classifier is "" (empty string). I suspect that the issue is with the
latter, which should probably be "tests". I will try this weekend to
modify the implementation so that if
`DependencyCoordinate.getClassifier()` is "", then
`DependencyCoordinate.getType().getClassifier()` is used as a fallback.
Martin
Re: Status of new compiler plugin for Maven 4
Posted by Guillaume Nodet <gn...@apache.org>.
Le lun. 22 juil. 2024 à 18:41, Martin Desruisseaux
<ma...@geomatys.com> a écrit :
>
> Hello all
>
> The work on a new maven-compiler-plugin [1] for Maven 4 has reached the
> following state:
>
> * All existing JUnit tests pass
> * Integration tests do not yet pass (I'm working on that)
> * Plexus compiler dependency completely removed (replaced by javax.tools)
Awesome work ! Does ECJ implement javax.tools API too ?
>
> My current issue is that dependencies of type "test-jar" are lost. I'm
> not sure if I'm doing something wrong or if this is an issue with Maven
> core. The code looks like that:
>
> DependencyResolver resolver = session.getService(DependencyResolver.class);
> DependencyResolverResult dependencies
> .session(session)
> .project(project)
> .pathScope(PathScope.TEST_COMPILE)
> .build());
>
> In a step-by-step debugging, I see that
> org.apache.maven.internal.impl.AbstractSession.toDependency(…) is
> invoked for transforming a dependency from Maven model to Aether model
> as below (line 274):
>
> new org.eclipse.aether.artifact.DefaultArtifact(
> dependency.getGroupId(),
> dependency.getArtifactId(),
> dependency.getClassifier(),
> dependency.getType().getExtension(),
> dependency.getVersion().toString(),
> null)
>
> I did not saw the "test-jar" anywhere in the copied object, or did I
> missed something? Or is this code supposed to generate automatically a
> "tests" classifier when the type is "type-jar"?
>
> Generally speaking, having coexisting models such as Maven and Eclipse
> Aether with conversions between those models makes more difficult to
> follow what is happening inside Maven core, and is a risk of data lost.
> Don't we have an overlap between the following interfaces, and if yes,
> should we try to reduce the overlap?
>
> * org.eclipse.aether.graph.Dependency
> * org.apache.maven.api.Dependency
> * org.apache.maven.api.DependencyCoordinate
The org.eclipse.aether.graph.Dependency objects should not be used and
will not even be exposed once/if [1] is merged. One of the goals of
the Maven 4 API was to hide the resolver completely, so I'm not sure
how to not wrap those. But if you have some suggestions...
For this particular point, there are really only two implementations
of org.apache.maven.api.DependencyCoordinate which are
org.apache.maven.internal.impl.DefaultDependencyCoordinate and the
anonymous class defined in
org.apache.maven.internal.impl.DefaultProject, which wraps a
org.apache.maven.api.model.Dependency. Both should have the getType()
return a correct value, so passing null to the
org.eclipse.aether.artifact.DefaultArtifact constructor [2] definitely
looks like a bug.
[1] https://github.com/apache/maven/pull/1336
[2] https://github.com/apache/maven/blob/d35864e348e84e2246fafe242fa732b58980a4cf/maven-api-impl/src/main/java/org/apache/maven/internal/impl/AbstractSession.java#L305
>
> Thanks,
>
> Martin
>
> [1]https://github.com/Geomatys/maven-compiler-plugin
--
------------------------
Guillaume Nodet
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Status of new compiler plugin for Maven 4
Posted by Konrad Windszus <kw...@apache.org>.
Hi Martin,
First of all thanks a lot for the hard work. Much appreciated.
However there is other compilers like the Groovy Eclipse Compiler (https://github.com/groovy/groovy-eclipse/blob/d6ac73c6ba4adadbd67c60bf130ad68f2284890f/extras/groovy-eclipse-compiler/src/main/java/org/codehaus/groovy/eclipse/compiler/GroovyEclipseCompiler.java#L71C14-L71C35) which doesn’t implement javax.tools.JavaCompiler (yet).
I opened https://github.com/groovy/groovy-eclipse/issues/1592 to raise an improvement request regarding this.
Konrad
> On 23. Jul 2024, at 10:58, Martin Desruisseaux <ma...@geomatys.com> wrote:
>
> Le 2024-07-23 à 10 h 50, András Péteri a écrit :
>>
>> Class "org.eclipse.jdt.internal.compiler.tool.EclipseCompiler" does implement this interface (…snip…) name() is a default method on javax.tools.Tool and this implementation leaves it as-is, so it will return an empty String.
>>
> Looks good. I also see that this compiler is declared in META-INF:
>
> https://github.com/eclipse-jdt/eclipse.jdt.core/blob/8e630b6c235edaf7d6e757442b1ee2c5761b6021/org.eclipse.jdt.core.compiler.batch/META-INF/services/javax.tools.JavaCompiler
>
> Then a pull request for adding a name() method returning (I guess) "ecj" should be everything needed. Putting the Eclipse JAR file on the class-path at maven-compiler-plugin execution time would be sufficient for making this compiler available.
>
> Martin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
Re: Status of new compiler plugin for Maven 4
Posted by Martin Desruisseaux <ma...@geomatys.com>.
Le 2024-07-23 à 10 h 50, András Péteri a écrit :
>
> Class "org.eclipse.jdt.internal.compiler.tool.EclipseCompiler" does
> implement this interface (…snip…) name() is a default method on
> javax.tools.Tool and this implementation leaves it as-is, so it will
> return an empty String.
>
Looks good. I also see that this compiler is declared in META-INF:
https://github.com/eclipse-jdt/eclipse.jdt.core/blob/8e630b6c235edaf7d6e757442b1ee2c5761b6021/org.eclipse.jdt.core.compiler.batch/META-INF/services/javax.tools.JavaCompiler
Then a pull request for adding a name() method returning (I guess) "ecj"
should be everything needed. Putting the Eclipse JAR file on the
class-path at maven-compiler-plugin execution time would be sufficient
for making this compiler available.
Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Status of new compiler plugin for Maven 4
Posted by András Péteri <ap...@b2ihealthcare.com.INVALID>.
Class "org.eclipse.jdt.internal.compiler.tool.EclipseCompiler" does
implement this interface (although I don't know if this is the exact class
that is used for compilation within Maven builds):
https://github.com/eclipse-jdt/eclipse.jdt.core/blob/8e630b6c235edaf7d6e757442b1ee2c5761b6021/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java#L49
name() is a default method on javax.tools.Tool and this implementation
leaves it as-is, so it will return an empty String.
On Tue, Jul 23, 2024 at 10:40 AM Martin Desruisseaux <
martin.desruisseaux@geomatys.com> wrote:
> Le 2024-07-23 à 05 h 20, Olivier Lamy a écrit :
> >
> > How to use ecj with those changes? Or any other external tool by using
> > the executable configuration?
> >
> The compiler needs to implement the following interface (I think it is
> the case of the Eclipse compiler, but didn't verified carefully):
>
> javax.tools.JavaCompiler
>
> That interface inherits a name() method, which returns a String. That
> method needs to return a unique identifier. For the standard Java
> compiler, that identifier is "javac". The javax.tools specification
> recommends to use an identifier which is the same as the command invoked
> on the command-line.
>
> Then, the following file must be present in the JAR file and shall
> contain the fully-qualified name of the JavaCompiler implementation (in
> the future, we should allow to replace that requirement by a module-info
> file).
>
> META-INF/services/javax.tools.Tool
>
> Finally, in the maven-compiler-plugin configuration declared in the
> pom.xml file, the <compilerId> element shall contain the above-cited
> identifier. The maven-compiler-plugin iterates over the tools using
> java.util.ServiceLoader until it find a tool with a name matching the
> compilerId. This mechanism is tested in the JUnit tests with two
> `CompilerStub` implementations.
>
> Martin
>
>
--
András
Re: Status of new compiler plugin for Maven 4
Posted by Martin Desruisseaux <ma...@geomatys.com>.
Le 2024-07-23 à 05 h 20, Olivier Lamy a écrit :
>
> How to use ecj with those changes? Or any other external tool by using
> the executable configuration?
>
The compiler needs to implement the following interface (I think it is
the case of the Eclipse compiler, but didn't verified carefully):
javax.tools.JavaCompiler
That interface inherits a name() method, which returns a String. That
method needs to return a unique identifier. For the standard Java
compiler, that identifier is "javac". The javax.tools specification
recommends to use an identifier which is the same as the command invoked
on the command-line.
Then, the following file must be present in the JAR file and shall
contain the fully-qualified name of the JavaCompiler implementation (in
the future, we should allow to replace that requirement by a module-info
file).
META-INF/services/javax.tools.Tool
Finally, in the maven-compiler-plugin configuration declared in the
pom.xml file, the <compilerId> element shall contain the above-cited
identifier. The maven-compiler-plugin iterates over the tools using
java.util.ServiceLoader until it find a tool with a name matching the
compilerId. This mechanism is tested in the JUnit tests with two
`CompilerStub` implementations.
Martin
Re: Status of new compiler plugin for Maven 4
Posted by Olivier Lamy <ol...@apache.org>.
very good work.
How to use ecj with those changes?
Or any other external tool by using the executable configuration?
On Tue, 23 Jul 2024 at 02:43, Martin Desruisseaux
<ma...@geomatys.com> wrote:
>
> Hello all
>
> The work on a new maven-compiler-plugin [1] for Maven 4 has reached the
> following state:
>
> * All existing JUnit tests pass
> * Integration tests do not yet pass (I'm working on that)
> * Plexus compiler dependency completely removed (replaced by javax.tools)
>
> My current issue is that dependencies of type "test-jar" are lost. I'm
> not sure if I'm doing something wrong or if this is an issue with Maven
> core. The code looks like that:
>
> DependencyResolver resolver = session.getService(DependencyResolver.class);
> DependencyResolverResult dependencies
> .session(session)
> .project(project)
> .pathScope(PathScope.TEST_COMPILE)
> .build());
>
> In a step-by-step debugging, I see that
> org.apache.maven.internal.impl.AbstractSession.toDependency(…) is
> invoked for transforming a dependency from Maven model to Aether model
> as below (line 274):
>
> new org.eclipse.aether.artifact.DefaultArtifact(
> dependency.getGroupId(),
> dependency.getArtifactId(),
> dependency.getClassifier(),
> dependency.getType().getExtension(),
> dependency.getVersion().toString(),
> null)
>
> I did not saw the "test-jar" anywhere in the copied object, or did I
> missed something? Or is this code supposed to generate automatically a
> "tests" classifier when the type is "type-jar"?
>
> Generally speaking, having coexisting models such as Maven and Eclipse
> Aether with conversions between those models makes more difficult to
> follow what is happening inside Maven core, and is a risk of data lost.
> Don't we have an overlap between the following interfaces, and if yes,
> should we try to reduce the overlap?
>
> * org.eclipse.aether.graph.Dependency
> * org.apache.maven.api.Dependency
> * org.apache.maven.api.DependencyCoordinate
>
> Thanks,
>
> Martin
>
> [1]https://github.com/Geomatys/maven-compiler-plugin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org