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

[JENKINS-67912] Maven HPI plugin does not compile with Java 11 #310

Merged
merged 3 commits into from
Mar 22, 2022

Conversation

basil
Copy link
Member

@basil basil commented Mar 22, 2022

Problem

See JENKINS-67912. When compiling maven-hpi-plugin with Java 11, the build fails:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.0:compile (default-compile) on project maven-hpi-plugin: Compilation failure
[ERROR] java.nio.file.NoSuchFileException: jenkinsci/maven-hpi-plugin/target/classes/META-INF/exposed.stapler-beans
[ERROR] 
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.0:compile (default-compile) on project maven-hpi-plugin: Compilation failure
java.nio.file.NoSuchFileException: jenkinsci/maven-hpi-plugin/target/classes/META-INF/exposed.stapler-beans

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
java.nio.file.NoSuchFileException: jenkinsci/maven-hpi-plugin/target/classes/META-INF/exposed.stapler-beans

    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1300)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:198)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Evaluation

This error seems to be caused by the use of maven-stapler-plugin as a direct dependency. The comment states: "for using annotation processor", but this seems to be outdated. The logic dates from commit 334506f from 2007, and the annotation logic was ripped out in commit 334506f in 2012. So this dependency is just no longer needed. Plugins and core consume maven-stapler-plugin through their respective parent POMs. This is not needed in maven-hpi-plugin.

Solution

Remove maven-stapler-plugin. This opens a can of worms, as it seems we were unintentionally relying on maven-stapler-plugin to pull in:

  • Ant
  • Guava
  • Maven 2 (!)

So now we explicitly depend on the latest versions of Ant and Guava (which we consume directly) and rewrite any usages of Maven 2 in terms of the equivalent Maven 3 APIs.

Implementation

The main Maven 2 API we were still consuming was org.apache.maven.project.MavenProjectBuilder#buildFromRepository. This PR rewrites our usages in terms of the Maven 3 API org.apache.maven.project.ProjectBuilder#build instead.

Testing done

I tested this both from plugins and core. In the case of core I verified that the generate-taglib-interface Mojo still produced the same results as before. In the case of plugins I verified that the resulting .hpi had the same contents as before and that mvn hpi:run still worked as before.

Fixes #286

new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
buildingRequest.setRemoteRepositories(remoteRepositories);
buildingRequest.setLocalRepository(localRepository);
buildingRequest.setProcessPlugins(false); // improve performance
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling the processing of plugins has a significant effect on performance. I noticed build times had doubled compared to before this PR. Investigating further, I suspected the the Maven 2 APIs we were using before this PR never processed plugins. When I disabled plugin processing in fc9ae1e, performance went back to its old levels. You can see the difference between build 1 and build 2 of this PR. Build 1 took 29 minutes; build 2 took 12 minutes. Builds of the main branch typically take 15 minutes. So this PR keeps performance at similar levels. I repeated the manual testing I had done in core and plugins, and processing plugins didn't seem to have any noticeable effect.

Copy link
Member

@Vlatombe Vlatombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me as far as I can tell.

@basil basil merged commit af64e0c into jenkinsci:master Mar 22, 2022
@basil basil deleted the JENKINS-67912 branch March 22, 2022 13:57
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoot, too late

pom.xml Show resolved Hide resolved
pom.xml Show resolved Hide resolved
@jglick
Copy link
Member

jglick commented Mar 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

maven-hpi-plugin does not compile with Java 11
3 participants