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

ECJ usage broken in 2.14.x #347

Closed
kriegaex opened this issue Dec 29, 2023 · 29 comments · Fixed by #361
Closed

ECJ usage broken in 2.14.x #347

kriegaex opened this issue Dec 29, 2023 · 29 comments · Fixed by #361

Comments

@kriegaex
Copy link
Contributor

kriegaex commented Dec 29, 2023

Create a new project (no sources needed) with this POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.acme</groupId>
  <artifactId>example</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <properties>
    <!-- 2.13.0 works, 2.14.x yields error "No such compiler 'eclipse'" -->
    <plexus-compiler.version>2.14.2</plexus-compiler.version>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.12.1</version>
        <configuration>
          <compilerId>eclipse</compilerId>
          <source>11</source>
          <target>11</target>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-eclipse</artifactId>
            <version>${plexus-compiler.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

</project>

Running mvn compile -e yields:

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< org.acme:example >--------------------------
[INFO] Building example 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\alexa\Documents\java-src\JDTCore-gh-1676\_x\src\main\resources
[INFO] 
[INFO] --- compiler:3.12.1:compile (default-compile) @ example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.348 s
[INFO] Finished at: 2023-12-29T09:55:07+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.12.1:compile (default-compile) on project example: No such compiler 'eclipse'. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.12.1:compile (default-compile) on project example: No such compiler 'eclipse'.
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: No such compiler 'eclipse'.
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:683)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:212)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

The result is the same on 2.14.0, 2.14.1, 2.14.2. With 2.13.0, it works.

@kriegaex kriegaex changed the title Using ECJ broken in 2.14.x ECJ usage broken in 2.14.x Dec 29, 2023
@slawekjaranowski
Copy link
Member

What version of Maven do you use?

Similar to #332

@kriegaex
Copy link
Contributor Author

3.9.5. I quickly tried a few others for you: 3.9.4, 3.8.5, 3.6.3 - same result.

4.0.0-alpha-10 seems to work, at least in this empty project. Does that help you in any way? Have you tried to reproduce? It is really super simple, you only need the POM.

@slawekjaranowski
Copy link
Member

You need at least 3.9.6 - https://issues.apache.org/jira/browse/MNG-7913

@pzygielo
Copy link
Contributor

@kriegaex
Copy link
Contributor Author

kriegaex commented Dec 30, 2023

Yes, it works on 3.9.6, thank you.

Hm, that error message is not so nice, as you can see from the duplicate issue here. If a minor library version upgrade forces a project to upgrade to the latest Maven release, I am expecting a more helpful error message, not just "No such compiler 'eclipse'". Could you please improve that? Imagine thousands of developers around the world getting Dependabot or Renovate suggestions to upgrade, and then there is this error message they do not understand, creating unnecessary work here like I did.

BTW, it is really unfortunate to change an important core library in a minor-minor Maven version, just because the old one does not support annotation scanning on JDK 17+, causing a breaking change for all plugins which need same annotation scanning. Of course, it is not Maven's fault that ECJ requires JDK 17+ now, also forcing its fork AJC to upgrade. So, I understand that in order to use ECJ or AspectJ with Plexus Compilers, JDK 17+ (as a build environment, not as a runtime environment for the compiled programs) is necessary, too. But that this forces users to upgrade to Maven 3.9.6 because of the breaking switch to Sisu, even though they previously had compiled their problems without any problems on Java 17 or 21 with Maven 3.9.5 or older, is really counter-intuitive. It would have been nice, if the old library could have been kept alive until a breaking change in Maven 4.

Anyway, sorry for straying off topic. A better error message is what I think justifies keeping this issue open.

@slachiewicz
Copy link
Member

@kriegaex it is not breaking change in Maven. It's just a consequence of Eclise ECJ requiring Java 17.
In Maven we just added enhancement thanks to the upgrade of Eclise SIsiu to discover components compiled with Java 17.

Feel free to open PR with improvements to maven-compiler-plugin

@kriegaex
Copy link
Contributor Author

kriegaex commented Jan 9, 2024

it is not breaking change

Fine, then it simply has stopped working without a helpful error message.

I wonder why the default answer to users asking for something so often is "feel free to open a PR", instead of remembering to be a committer and improve something oneself. Am I really asking too much, hoping for a better, more informative error message?

@kriegaex
Copy link
Contributor Author

kriegaex commented Jan 10, 2024

@slachiewicz, @slawekjaranowski, can you please explain to me how DefaultCompilerManager.compilers is populated? I see that it is injected, but I do not understand how whatever scans this then decides which compilers to add to the map and which to skip. I would like to take a look at that, because IMO it was not a good decision to require Java 17 for ECJ, AJC and IT modules in Plexus Compiler. Look at how AspectJ.dev AspectJ Maven does it:

https://github.com/dev-aspectj/aspectj-maven-plugin/blob/c544e63fb017a6dae10d968c64d4d4acb505ec4e/pom.xml#L331-L342

The enforcer rule just skips aspectjtools and lets the errors occur on runtime, which is better, because then the user better understands what is wrong. The same could be done for ecj. Plus, it would enable users to downgrade ECJ and AJC to older versions in the plugin dependencies, if they decide to work with older compiler versions requiring only Java 11. Just because somebody upgrades Plexus, does not mean they need to be forced to upgrade Maven, AspectJ or ECJ.

@slachiewicz
Copy link
Member

slachiewicz commented Jan 10, 2024

Eclipse Sisu does classpath scanning for classes annotated with @Named
If we have an older maven, Sisu cannot read classes compiled to Java 14+ and the map will not be populated.

@kriegaex
Copy link
Contributor Author

kriegaex commented Jan 11, 2024

This problem is not solved even in Maven 3.9.6. Just compile the same POM on a JDK older than 17. Even though Sisu-Inject 0.9.0.M2 contains ASM capable of parsing class files up to Java 21 and depends on Guice 5.1.0, which also contains its own relocated copy of ASM, but this time the highest class file version it knows is JDK 18. Both should be enough to parse (annotations on) Java 17 class files even when running the build on JDK 8, 11 or 16, then populate the compilers list and try to run e.g. Eclipse or AspectJ compilers, then probably failing due to unknown class file versions on the older JDK running the build, which would give users a clear indicator of what it wrong.

So, either there is yet another ASM somewhere in the belly of Maven or Maven Compiler, or maybe it is something else like CGLIB or whatever else it uses.

@kriegaex
Copy link
Contributor Author

kriegaex commented Jan 11, 2024

I was able to reproduce the problem locally with a mini Sisu project, compiling the class receiving the injection to target 8 and the @Named classes to be scanned to target 17. When running the program on JDK less than 17, simply nothing happens, no exception. Sisu simply catches the error. Only when running the JVM with -Dsisu.debug, I can finally see log output like this:

...
DEBUG: Sisu - Problem scanning: file:/C:/Users/alexa/Documents/java-src/plexus-compiler/_sisu/target/classes/example/RadioButtonTab.class
java.lang.TypeNotPresentException: Type example.RadioButtonTab not present
        at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:147)
        at org.eclipse.sisu.space.QualifiedTypeVisitor.leaveClass(QualifiedTypeVisitor.java:128)
        at org.eclipse.sisu.space.SpaceScanner$1.visitEnd(SpaceScanner.java:180)
        at org.eclipse.sisu.space.asm.ClassReader.accept(ClassReader.java:748)
        at org.eclipse.sisu.space.asm.ClassReader.accept(ClassReader.java:424)
...
Caused by: java.lang.UnsupportedClassVersionError: example/RadioButtonTab has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
...
DEBUG: Sisu - Potential problem: example.Example
java.lang.UnsupportedClassVersionError: example/AbstractTab has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 60.0
...
TRACE: Sisu - Discard binding: UntargettedBinding{key=Key[type=example.Example, annotation=[none]], source=/C:/Users/alexa/Documents/java-src/plexus-compiler/_sisu/target/classes/}
TRACE: Sisu - Discard binding: LinkedKeyBinding{key=Key[type=java.lang.Object, annotation=*], source=/C:/Users/alexa/Documents/java-src/plexus-compiler/_sisu/target/classes/, scope=Scopes.NO_SCOPE, target=Key[type=example.Example, annotation=[none]]}

This is caused by the ASM class visitor here.

Just run the build for my POM on JDK less than 17 with Maven 3.9.6, and you will see what Sisu does:

MAVEN_OPTS=-Dsisu.debug mvn -V compile >build.log 2>&1

Then inspect the log:

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: C:\Program Files\Java\apache-maven-3.9.6
Java version: 11.0.10, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.10
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
TRACE: Sisu - Add publisher: com.google.inject.internal.InjectorImpl@69eb86b4

-----[explicit bindings]-------------------------------------------------------
...
[INFO] --- compiler:3.12.1:compile (default-compile) @ example ---
WARN: Sisu - Inconsistent ClassLoader for: interface com.google.inject.Module in: ClassRealm[plugin>org.apache.maven.plugins:maven-compiler-plugin:3.12.1, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@2cdf8d8a]
WARN: Sisu - Expected: ClassRealm[plexus.core, parent: null] saw: ClassRealm[plugin>org.apache.maven.plugins:maven-compiler-plugin:3.12.1, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@2cdf8d8a]
DEBUG: Sisu - Problem scanning: jar:file:/C:/Users/alexa/.m2/repository/org/codehaus/plexus/plexus-compiler-eclipse/2.14.2/plexus-compiler-eclipse-2.14.2.jar!/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.class
java.lang.TypeNotPresentException: Type org.codehaus.plexus.compiler.eclipse.EclipseJavaCompiler not present
	at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:147)
	at org.eclipse.sisu.space.QualifiedTypeVisitor.leaveClass(QualifiedTypeVisitor.java:128)
	at org.eclipse.sisu.plexus.PlexusTypeVisitor.leaveClass(PlexusTypeVisitor.java:117)
	at org.eclipse.sisu.space.SpaceScanner$1.visitEnd(SpaceScanner.java:180)
	at org.eclipse.sisu.space.asm.ClassReader.accept(ClassReader.java:748)
	at org.eclipse.sisu.space.asm.ClassReader.accept(ClassReader.java:424)
	at org.eclipse.sisu.space.SpaceScanner.accept(SpaceScanner.java:102)
	at org.eclipse.sisu.space.SpaceScanner.accept(SpaceScanner.java:78)
...
Caused by: java.lang.UnsupportedClassVersionError: org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
...

So, the problem does not actually seem to be parsing the class with ASM and finding the annotations, but rather Sisu trying to load the class in URLClassSpace.loadClass. There is no option to throw an error, if a problem like that occurs, hence Maven or Maven Compiler also cannot catch any exceptions, trying to print a better error message. I have no deep insights in what Sisu does here, but if it simply tries to populate the list/map of compilers, it would not need to actually load them yet. Then later, when trying to run one of them, there would be a regular unsupported class version error, which the user could see.

Is there, to the best of your knowledge, any way to scan the annotations without actually loading the classes? I certainly know that ASM can do that, but it depends on how Sisu uses ASM.

@laeubi
Copy link
Contributor

laeubi commented Jan 30, 2024

it is not breaking change in Maven. It's just a consequence of Eclise ECJ requiring Java 17.

This is only partly true, it is a consequence of using @Named... with @Component it works like a charm with older maven versions and that's the reason we didn't upgraded to the "better" @Named in Tycho yet .. and Maven was broken before. Another "fix" is to compile the component code with Java 11 bytecode (even though it makes not much sense if runtime requires java 17 anyways)

So even that @Component is "old school" it did a better job by defer the class scanning and problem diagnostic to the build-time rather than runtime.

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

Two pieces of new information:

  1. I created Option to propagate exceptions in SpaceScanner.accept eclipse-sisu/sisu-project#108, which, as I noticed later, seems to be a duplicate of Do not silently fail in SpaceScanner when classes could not be parsed eclipse-sisu/sisu-project#97. For the latter, there is a PR Do not silently fail in case of class scanning exceptions eclipse-sisu/sisu-project#98, which should be watched. Both Maven Compiler and Plexus Compiler should be able to utilise the new configurable option to propagate exceptions to handle them in a more user-friendly way, as soon as it is available.

  2. The stacktrace for the actual POM in this issue (not for minimal, pure Sisu project) when running mvn compile -Dsisu.debug:

DEBUG: Sisu - Problem scanning: jar:file:/C:/Users/alexa/.m2/repository/org/codehaus/plexus/plexus-compiler-eclipse/2.14.3-SNAPSHOT/plexus-compiler-eclipse-2.14.3-SNAPSHOT.jar!/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.class
java.lang.TypeNotPresentException: Type org.codehaus.plexus.compiler.eclipse.EclipseJavaCompiler not present
	at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:147)
	at org.eclipse.sisu.space.QualifiedTypeVisitor.leaveClass(QualifiedTypeVisitor.java:128)
	at org.eclipse.sisu.plexus.PlexusTypeVisitor.leaveClass(PlexusTypeVisitor.java:117)
	at org.eclipse.sisu.space.SpaceScanner$1.visitEnd(SpaceScanner.java:180)
	at org.eclipse.sisu.space.asm.ClassReader.accept(ClassReader.java:748)
	at org.eclipse.sisu.space.asm.ClassReader.accept(ClassReader.java:424)
	at org.eclipse.sisu.space.SpaceScanner.accept(SpaceScanner.java:102)
	at org.eclipse.sisu.space.SpaceScanner.accept(SpaceScanner.java:78)
	at org.eclipse.sisu.space.SpaceModule.scanForElements(SpaceModule.java:169)
	at org.eclipse.sisu.space.SpaceModule.configure(SpaceModule.java:130)
	at org.eclipse.sisu.plexus.PlexusAnnotatedBeanModule.configure(PlexusAnnotatedBeanModule.java:102)
	at org.eclipse.sisu.plexus.PlexusBindingModule.configure(PlexusBindingModule.java:63)
	at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:409)
	at com.google.inject.spi.Elements.getElements(Elements.java:108)
	at com.google.inject.spi.Elements.getElements(Elements.java:101)
	at org.eclipse.sisu.wire.WireModule.configure(WireModule.java:75)
	at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:409)
	at com.google.inject.spi.Elements.getElements(Elements.java:108)
	at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:160)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
	at com.google.inject.Guice.createInjector(Guice.java:87)
	at com.google.inject.Guice.createInjector(Guice.java:69)
	at com.google.inject.Guice.createInjector(Guice.java:59)
	at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:482)
	at org.codehaus.plexus.DefaultPlexusContainer.discoverComponents(DefaultPlexusContainer.java:461)
	at org.apache.maven.plugin.internal.DefaultMavenPluginManager.discoverPluginComponents(DefaultMavenPluginManager.java:410)
	at org.apache.maven.plugin.internal.DefaultMavenPluginManager.createPluginRealm(DefaultMavenPluginManager.java:392)
	at org.apache.maven.plugin.internal.DefaultMavenPluginManager.lambda$setupPluginRealm$1(DefaultMavenPluginManager.java:340)
	at org.apache.maven.plugin.DefaultPluginRealmCache.lambda$get$0(DefaultPluginRealmCache.java:156)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at org.apache.maven.plugin.DefaultPluginRealmCache.get(DefaultPluginRealmCache.java:154)
	at org.apache.maven.plugin.internal.DefaultMavenPluginManager.setupPluginRealm(DefaultMavenPluginManager.java:339)
	at org.apache.maven.plugin.DefaultBuildPluginManager.getPluginRealm(DefaultBuildPluginManager.java:205)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:98)
	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
	at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
	at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
	at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: java.lang.UnsupportedClassVersionError: org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.findClassInternal(ClassRealm.java:313)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:432)
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	at org.eclipse.sisu.space.URLClassSpace.loadClass(URLClassSpace.java:139)
	... 60 more

I.e., we are looking at a java.lang.TypeNotPresentException caused by a UnsupportedClassVersionError, just like in the minimal Sisu example I created for myself. This confirms, that my example reproduces the error correctly. The not so good news is that in the stack trace, I can see neither Maven Compiler nor Plexus Compiler classes. It looks as if the error would propagate all the way up to the Plexus Classworlds Launcher, unless caught somewhere along the way. Does anyone here know enough about Plexus and Maven internals to have an idea how to propagate the error into the plugin actually containing or requiring the JAR which cannot be (fully) scanned? I think, Plexus Compiler should decide what kind of error message or warning to issue in this case. But to be able to do that, it must know that the error actually occurred.

CC @kwin, @cstamas.

@kwin
Copy link
Contributor

kwin commented Feb 1, 2024

Due to the way dependency injection works it is not possible for m-compiler-p to come up with a better error message than No such compiler 'eclipse'.. But in case the underlying Sisu/Plexus container is configured to fail with an exception the behaviour will be that Maven will not even start in case of unparseable components and Maven will emit an according error message. For this we need eclipse-sisu/sisu.plexus#51 first though, and then an according fix on the Maven side.

@laeubi
Copy link
Contributor

laeubi commented Feb 1, 2024

Has someone tried to simply compile the org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler with target level 11?

Another way would be do make it a Multi-Release-Jar and have there a org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler that simply throws an exception with a suitable hint whats going on.

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

@kwin, of course I was implying that eclipse-sisu/sisu.plexus#51 is implemented, because it is linked to the other issue. BTW, there is always a way to make something work. In this case, downstream projects need to wait for upstream projects to enable a solution, which is as a mere user I was trying to connect the Sisu people and the Maven people to each other, so they can figure out the best solution together.

Even today, there would be an ugly way to make it work: Make Sisu Inject do its log output, capture it (optionally tee-ing it to the console or log file, if the user actually sets the debug option) and react to certain things we find there. I am not suggesting to do it this way, but in theory, it would be possible.

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

Has someone tried to simply compile the org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler with target level 11?

Yes, that is exactly what I tried first locally. It is not helping, because Sisu is not just parsing the class with ASM, but also loading it for whatever reason. But EclipseJavaCompiler directly imports org.eclipse.jdt.core.compiler.CompilationProgress and org.eclipse.jdt.core.compiler.batch.BatchCompiler, both of which are Java 17 class files. So either we need a way to make Sisu parse and scan class files without loading/defining them, which from my point of view ASM could do just fine, or for Sisu Inject to optionally throw exceptions and changing Maven in such a way that Plexus Compiler can be notified of it and react to it.

@laeubi
Copy link
Contributor

laeubi commented Feb 1, 2024

Yes, that is exactly what I tried first locally. It is not helping, because Sisu is not just parsing the class with ASM, but also loading it for whatever reason. But EclipseJavaCompiler directly imports

The Multi-Release Jar would be an option...

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

Option 3 would be to refactor both EclipseJavaCompiler and AspectJCompiler to not directly interact with their respective compiler classes but factor out whatever they into other classes, which are not automatically loaded while scanning them for annotations, solving the problem that way. Hm, that might be worth exploring. A hybrid solution would be to use reflection to lazily get method handles when they are needed and dispatch to the upstream compiler classes only when actually trying to compile something.

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

The Multi-Release Jar would be an option...

How so?

Edit: Forget the question. I missed that at first:

Another way would be do make it a Multi-Release-Jar and have there a org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler that simply throws an exception with a suitable hint whats going on.

Yes, that would work. I am, however, not claiming to be the champion of multi-release JARs. Other than knowing that they exist and how they basically work, I never used them before. It might also require extra tests for both cases. But of course, that would be true for my "option 3" solution, too. Let me think about it. I do hope that one of the committers here solves the problem first, because I am currently dancing on several other weddings already. Otherwise, I might be able to come up with some kind of ugly, but functioning workaround.

@laeubi
Copy link
Contributor

laeubi commented Feb 1, 2024

Its not that hard, you just need to have two executions of the compiler with different release levels, its just not hat nice in the IDE (usually you have to work on one of them but not both).

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

Yes, the IDE bit is what always kept me from exploring it more deeply than in theory. AspectJ uses the reflection + method handles approach in situations like that. Of course, that is ugly too in a way, especially because it sort of obfuscates the code. OTOH, that makes the maintainer a demigod to some people. 😂😂😂

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 1, 2024

I have a local PoC for the multi-release JAR approach for ECJ. Actually, for AspectJ it is not strictly necessary, because AspectJCompiler imports more classes, but AspectJ tries to compile to target 8 wherever possible. I.e., there will just be a runtime error, if compile something needing Java 17 JDT Core classes, but Sisu can scan the class without any changes, if we compile it to target 11.

Tomorrow, I will push a draft PR to get some feedback from the committers here. The rest of the evening (in my current time zone), I will be busy.

kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 2, 2024
AspectJ can compile many projects on JDK 11, because it is not always
using Java 17 classes from JDT Core. If it does not work, there will be
a runtime error, and the user can figure out what is wrong.

For ECJ, the case is more complicated, because it directly imports Java
17 classes from JDT Core. There were isolated in new class
EclipseJavaCompilerDelegate, which is accessed using Class::forName and
method handles from EclipseJavaCompiler.

I.e., Sisu Inject can scan the annotations on EclipseJavaCompiler on
JDK 11, and there is no more confusing "No such compiler 'eclipse'"
error, but rather:

Error injecting constructor, ... EcjFailureException:
Failed to run the ecj compiler: ECJ only works on Java 17+
  at org.codehaus.plexus.compiler.eclipse.EclipseJavaCompiler.<init>

This explicitly tells the user what is wrong.

A multi-release JAR solution was tested and worked well in Maven, but
was dismissed due to the terrible developer experience in IDEs.

Fixes codehaus-plexus#347.
@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 2, 2024

I would appreciate feedback to PR #358.

kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 2, 2024
This shifts the focus from a supposed Maven component wiring error to
the root cause, expressed in the error message: "ECJ needs JRE 17+".

The new static boolean field EclipseJavaCompiler.isJdkSupported also
enables us to write a simple unit test, asserting on the error message,
if the field value is false.

Relates to codehaus-plexus#347.
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 2, 2024
This shifts the focus from a supposed Maven component wiring error to
the root cause, expressed in the error message:

  Fatal error compiling: ECJ needs JRE 17+

We need to add safeguards throwing the exception in both methods
accessing class EclipseJavaCompilerDelegate, because we cannot predict
who calls which one first. Omitting one safeguard might lead to the
return of the infamous "No such compiler 'eclipse'" error.

The new static boolean field EclipseJavaCompiler.isJdkSupported also
enables us to write a simple unit test, asserting on the error message,
if the field value is false.

Relates to codehaus-plexus#347.
@cstamas
Copy link
Member

cstamas commented Feb 2, 2024

Just my 5 cents: maybe a pattern like this could work to produce sane(r) error messages
#359

It would be able to differentiate "not present" vs "present but cannot construct it" (due whatever reason).

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 2, 2024

@cstamas, did you test your change? The code you changed is never reached, according to extra log messages I put there. Therefore, the change does not solve the problem. The error message I see on JDK 11 is still "No such compiler 'eclipse'.". The class also seems to be unused, I can delete it without any consequences.

@cstamas
Copy link
Member

cstamas commented Feb 2, 2024

@kriegaex
Copy link
Contributor Author

kriegaex commented Feb 2, 2024

Sorry, I am not a committer to this project, just an indirect user via Maven Compiler (MC). As it turns out, MC depends on Plexus Compiler Manager (PCM), but PCM's own integration tests, which I tried to run and also used as templates for my own projects, do not override the dependency and hence use the version defined in MC. Unfortunately, dependency:tree does not show information about plugins, I needed dependency:resolve-plugins, which does not display a nice tree, but at least a list revealing the problem.

Now I see:

[INFO] --- compiler:3.12.1:compile (default-compile) @ example ---
[WARNING] Error injecting: org.apache.maven.plugin.compiler.CompilerMojo
com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) No implementation for CompilerManager was bound.
  while locating CompilerMojo

1 error

======================
Full classname legend:
======================
CompilerManager: "org.codehaus.plexus.compiler.manager.CompilerManager"
CompilerMojo:    "org.apache.maven.plugin.compiler.CompilerMojo"
========================
End of classname legend:
========================

    at com.google.inject.internal.InternalProvisionException.toProvisionException (InternalProvisionException.java:251)
    at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1104)
    at com.google.inject.internal.InjectorImpl.getInstance (InjectorImpl.java:1139)
    at org.eclipse.sisu.space.AbstractDeferredClass.get (AbstractDeferredClass.java:48)
    at com.google.inject.internal.ProviderInternalFactory.provision (ProviderInternalFactory.java:86)
    at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision (InternalFactoryToInitializableAdapter.java:57)
    at com.google.inject.internal.ProviderInternalFactory$1.call (ProviderInternalFactory.java:67)
    at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:109)
    at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision (ProvisionListenerStackCallback.java:124)
    at com.google.inject.internal.ProvisionListenerStackCallback.provision (ProvisionListenerStackCallback.java:66)
    at com.google.inject.internal.ProviderInternalFactory.circularGet (ProviderInternalFactory.java:62)
    at com.google.inject.internal.InternalFactoryToInitializableAdapter.get (InternalFactoryToInitializableAdapter.java:47)
    at com.google.inject.internal.InjectorImpl$1.get (InjectorImpl.java:1101)
    at org.eclipse.sisu.inject.Guice4$2.get (Guice4.java:233)
    at org.eclipse.sisu.inject.LazyBeanEntry.getValue (LazyBeanEntry.java:81)
    at org.eclipse.sisu.plexus.LazyPlexusBean.getValue (LazyPlexusBean.java:51)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:264)
    at org.codehaus.plexus.DefaultPlexusContainer.lookup (DefaultPlexusContainer.java:256)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo (DefaultMavenPluginManager.java:491)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:114)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)

I think, this is something I can take as a point of departure and develop a solution superior to my current PR. Thank you so much for your input.

kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails,
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changed in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changed in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails,
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changed in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails,
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changed in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails,
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changed in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changed in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails,
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails,
log a comprehensive error message on top of throwing a
NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
While testing codehaus-plexus#347, changes in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
If scanning, injection or construction fails, log a comprehensive error
message on top of throwing a NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 3, 2024
In order to be able to do that at all, I had to add a constructor taking
a throwable first. Now, even though a cause is propagated, at the time
of writing this Maven Compiler will just catch the
NoSuchCompilerException we throw, ignore its message and root cause and
throw a new MojoExecutionException instead. :-/

Relates to codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
@laeubi
Copy link
Contributor

laeubi commented Feb 4, 2024

@cstamas I wonder what would happen when one puts the following plugin descriptor(!)) inside the dependency that requires higher java/maven will it be considered if used as a dependency of another plugin?


<plugin>
  <name>Dummy Plugin</name>
  <groupId>plexus.compiler</groupId>
  <artifactId>ecj</artifactId>
  <version>..</version>
  <requiredJavaVersion>17</requiredJavaVersion>
  <requiredMavenVersion>3.9.0</requiredMavenVersion>
</plugin>

kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 4, 2024
While testing codehaus-plexus#347, changes in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 4, 2024
If scanning, injection or construction fails, log a comprehensive error
message on top of throwing a NoSuchCompilerException.

Fixes codehaus-plexus#347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 4, 2024
In order to be able to do that at all, I had to add a constructor taking
a throwable first. Now, even though a cause is propagated, at the time
of writing this Maven Compiler will just catch the
NoSuchCompilerException we throw, ignore its message and root cause and
throw a new MojoExecutionException instead. :-/

Relates to codehaus-plexus#347.
kriegaex added a commit to dev-aspectj/plexus-compiler that referenced this issue Feb 4, 2024
Add more detail concerning possible user errors like misspelling the
compiler ID or missing dependencies for a compiler.

Relates to codehaus-plexus#347.
slawekjaranowski pushed a commit that referenced this issue Feb 21, 2024
* ITs need plugin dependency to plexus-compiler-manager

While testing #347, changes in compiler manager were not pulled into
ITs, because Maven Compiler has a dependency on it, which must be
overridden in all ITs or in projects using Plexus Compiler generally, if
they need to override the version predefined by Maven Compiler.

* Lazy providers and better error reporting

If scanning, injection or construction fails, log a comprehensive error
message on top of throwing a NoSuchCompilerException.

Fixes #347.

Co-authored-by: Alexander Kriegisch <Alexander@Kriegisch.name>

* Code review: throw exception with cause

In order to be able to do that at all, I had to add a constructor taking
a throwable first. Now, even though a cause is propagated, at the time
of writing this Maven Compiler will just catch the
NoSuchCompilerException we throw, ignore its message and root cause and
throw a new MojoExecutionException instead. :-/

Relates to #347.

* Code review: improve DefaultCompilerManager.ERROR_MESSAGE

Add more detail concerning possible user errors like misspelling the
compiler ID or missing dependencies for a compiler.

Relates to #347.

---------

Co-authored-by: Tamas Cservenak <tamas@cservenak.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants