maven-enforcer
maven-enforcer copied to clipboard
[MENFORCER-473] Custom Rules are not processed with Java 17
Nils Christian Ehmke opened MENFORCER-473 and commented
Hi,
We noticed that our custom rule, using the newer API (as documented here) is not processed using Java 17.
We created a sample project using the custom rule example. Once we use Java 17 in the pom.xml it breaks.
<properties>
<api.version>3.2.1</api.version>
<maven.version>3.9.0</maven.version>
<!-- use JDK 1.8 at least -->
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<!-- generate index of project components -->
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>0.9.0.M1</version>
<executions>
<execution>
<goals>
<goal>main-index</goal>
</goals>
</execution>
</executions>
</plugin>
If we compile the custom rule and verify the using project, we get
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.2.1:enforce (enforce) on project maven-enforcer-plugin-sample-usage: Execution enforce of goal org.apache.maven.plugins:maven-enforcer-plugin:3.2.1:enforce failed: Failed to create enforcer rules with name: myCustomRule or for class: org.apache.maven.plugins.enforcer.MyCustomRule -> [Help 1]
The index file itself looks good, so something else within the plugin or Sisu Plexus seems to break.
Affects: 3.2.1
Issue Links:
- MNG-7587 Update Sisu to a version supporting at least Java 17 ("is blocked by")
- MNG-7913 Upgrade Sisu version to 0.9.0.M2
Remote Links:
1 votes, 6 watchers
Tamas Cservenak commented
This is current limitation with bundled Sisu in Maven (version 0.3.5): it is old, and uses old ASM, so only Java 11 bytecode is supported currently, as Sisu needs to introspect classes, the index file only tells which classes to look at. For any component that should run within Maven (so using provided Sisu container) the bytecode must not go beyond Java 11.
Nils Christian Ehmke commented
Hi Tamas Cservenak,
Thank you for the quick answer. Some follow-up questions:
- Can we somehow circumvent this? The documentation only shows how to implement custom rules using the new injection-based API, but can we still use the full qualified class name and evaluate the required Maven properties in another way instead of using an injected instance of {}MavenProject{}?
- Is there any roadmap on when/how this will be solved? Given that Java 17 has been released in 2021, it seems problematic that this has not somehow been adressed already. We are currently not able to use the never rules, e.g. {}banDependencyManagementScope{}.
- Shouldn't this be mentioned somewhere? Or is it documented and we just didn't see it?
Slawomir Jaranowski commented
Can we somehow circumvent this? The documentation only shows how to implement custom rules using the new injection-based API, but can we still use the full qualified class name and evaluate the required Maven properties in another way instead of using an injected instance of MavenProject?
Can you more clarify your requirements, cases in this subject?
Slawomir Jaranowski commented
Shouldn't this be mentioned somewhere? Or is it documented and we just didn't see it?
Should be, as we see we can only use JDK 8 or 11. Should be maintained at documentation about enforcer API.
Nils Christian Ehmke commented
Hi sjaranowski ,
Can you more clarify your requirements, cases in this subject?
Sure. We have rules evaluating expressions to get e.g. the resources folder of the Maven project:
protected Set<Path> getResourceFolders( final EnforcerRuleHelper helper ) throws EnforcerRuleException {
...
final List<Resource> resources = ( List<Resource> ) helper.evaluate( "${project.build.resources}" );
However, moving from Enforcer Plugin 3.0.0 to 3.2.1 a lot of the classes (e.g. the {}EnforcerRuleHelper{}) become deprecated, and classes for the evaluation are missing ("The type org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator cannot be resolved. It is indirectly referenced from required .class files").
The new way seems to simply inject MavenProject to retrieve such properties, but this is not possible with Java 17. So how do we solve this?
Tamas Cservenak commented
Sadly the (max) Java11 bytecode for components (and in Maven Mojos, and almost everything is a component) that are scanned by Sisu have this limitation, so to say this is more in fundaments of Maven, not Maven itself.
Eclipse Sisu we use is 0.3.5 (but same stands for M1 more recent release). Issues are https://github.com/eclipse/sisu.inject/issues/29 and https://github.com/eclipse/sisu.inject/issues/63 and hopefully soon Sisu 1.0 release will happen, and we also plan to pick up speed a bit on sisu that got a bit neglected.
In short, ANY component in Maven universe is tied by this limitation, that will be hopefully lifted with new Sisu release.
Slawomir Jaranowski commented
So the same as for Maven plugin you can use bytecode target max 11 for enforcer rules.
Ric Harris commented
I can confirm that Java 17 compiled rules do work with Maven 3.9.6+ - I have submitted a PR to align the documentation more explicitly, but this issue could now be closed.