Jenkins Plugin Development with JAVA 21

35 views
Skip to first unread message

Kul Bhushan Srivastava

unread,
May 16, 2025, 12:46:35 PM5/16/25
to jenkin...@googlegroups.com
Hi Team,

I am trying to compile my jenkins plugin project using java 21. Please help and suggest.

But getting below error.

[ERROR] [1;31mTests [0;1mrun: [0;1m1 [m, Failures: 0, [1;31mErrors: [0;1;31m1 [m, Skipped: 0, Time elapsed: 17.956 s [1;31m <<< FAILURE! [m - in [1mInjectedTest [m
[ERROR] org.jvnet.hudson.test.junit.FailedTest  Time elapsed: 0.006 s  <<< ERROR!
org.jvnet.hudson.reactor.ReactorException: java.lang.IllegalArgumentException: Unable to inject class hudson.model.UserIdMapper
at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:291)
at jenkins.InitReactorRunner.run(InitReactorRunner.java:49)
at jenkins.model.Jenkins.executeReactor(Jenkins.java:1195)
at jenkins.model.Jenkins.<init>(Jenkins.java:985)
at hudson.model.Hudson.<init>(Hudson.java:86)
at org.jvnet.hudson.test.HudsonTestCase.newHudson(HudsonTestCase.java:514)
at org.jvnet.hudson.test.HudsonTestCase.setUp(HudsonTestCase.java:342)
at org.jvnet.hudson.test.JellyTestSuiteBuilder$JellyTestSuite.setUp(JellyTestSuiteBuilder.java:130)
at org.jvnet.hudson.test.junit.GroupedTest.run(GroupedTest.java:49)
at junit.framework.TestSuite.runTest(TestSuite.java:241)
at junit.framework.TestSuite.run(TestSuite.java:236)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:72)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:55)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:223)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:175)
at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:135)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:456)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:169)
at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:595)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:581)
Caused by: java.lang.IllegalArgumentException: Unable to inject class hudson.model.UserIdMapper
at hudson.init.TaskMethodFinder.lookUp(TaskMethodFinder.java:130)
at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:110)
at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:185)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:305)
at jenkins.model.Jenkins$5.runTask(Jenkins.java:1160)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:222)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:121)
at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:70)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)

[INFO]
[INFO] Results:
[INFO]
[ERROR] [1;31mErrors: [m
[ERROR] [1;31m  FailedTest » Reactor java.lang.IllegalArgumentException: Unable to inject class hudson.model.UserIdMapper [m
[INFO]
[ERROR] [1;31mTests run: 1, Failures: 0, Errors: 1, Skipped: 0 [m
[INFO]
[INFO] [1m------------------------------------------------------------------------ [m
[INFO] [1;31mBUILD FAILURE

my pom.xml looks like below

<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 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <artifactId>STE</artifactId>
  <version>25.6</version>
  <packaging>hpi</packaging>

  <name>Test Executor Plugin</name>
  <description>A Jenkins plugin to execute tests via command line.</description>
  <url>https://github.com/your-org/siebel-test-executor</url>

  <properties>
    <java.level>21</java.level>
    <jenkins.version>2.361</jenkins.version>
    <hpi.plugin.version>3.45</hpi.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <enforcer.skip>true</enforcer.skip>
  </properties>
 

  <parent>
    <groupId>org.jenkins-ci.plugins</groupId>
    <artifactId>plugin</artifactId>
    <version>4.54</version>
    <relativePath/>
  </parent>

  <dependencies>
    <!-- Jenkins core APIs -->
    <dependency>
      <groupId>org.jenkins-ci.main</groupId>
      <artifactId>jenkins-core</artifactId>
      <version>${jenkins.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- Stapler for form binding -->
    <dependency>
      <groupId>org.kohsuke.stapler</groupId>
      <artifactId>stapler</artifactId>
      <version>1.263</version>
      <scope>provided</scope>
    </dependency>

    <!-- Add other plugin dependencies here if needed -->
    <dependency>
 <groupId>jakarta.servlet</groupId>
 <artifactId>jakarta.servlet-api</artifactId>
 <version>5.0.0</version> <!-- or match Jenkins core if needed -->
 <scope>provided</scope>
</dependency>

  </dependencies>

  <build>
    <plugins>
      <!-- Java 21 toolchain -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-toolchains-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <goals>
              <goal>toolchain</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <toolchains>
            <jdk>
              <version>21</version>
              <vendor>oracle</vendor> <!-- or adoptopenjdk/temurin -->
            </jdk>
          </toolchains>
        </configuration>
      </plugin>

      <!-- HPI packaging plugin -->
      <plugin>
        <groupId>org.jenkins-ci.tools</groupId>
        <artifactId>maven-hpi-plugin</artifactId>
        <version>${hpi.plugin.version}</version>
        <configuration>
          <pluginFirstClassLoader>true</pluginFirstClassLoader>
        </configuration>
      </plugin>

      <!-- Compiler plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
          <source>${java.level}</source>
          <target>${java.level}</target>
          <release>${java.level}</release>
        </configuration>
      </plugin>
     
      <plugin>
 <groupId>org.kohsuke</groupId>
 <artifactId>access-modifier-checker</artifactId>
 <version>1.34</version> <!-- >=1.34 supports Java 21 -->
 <executions>
   <execution>
     <goals>
       <goal>enforce</goal>
     </goals>
   </execution>
 </executions>
</plugin>


    </plugins>
  </build>

  <developers>
    <developer>
      <id>your-id</id>
      <name>Your Name</name>
      <email>y...@example.com</email>
    </developer>
  </developers>

  <licenses>
    <license>
      <name>MIT</name>
      <url>https://opensource.org/licenses/MIT</url>
    </license>
  </licenses>

</project>



--
Thanks & Regards
Kul Bhushan Srivastava
+91-7406000772

Jesse Glick

unread,
May 16, 2025, 3:49:59 PM5/16/25
to jenkin...@googlegroups.com
Delete all the stuff in your POM about Java 21. The Java level is determined by the Jenkins version. Please use a recent archetype: https://www.jenkins.io/doc/developer/tutorial/create/#create-the-project-layout-with-sample-plugin-archetype
Reply all
Reply to author
Forward
0 new messages