Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71123

java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • pipeline-maven-plugin
    • None
    • Jenkins 2.387.2. Install from UC: pipeline-maven, git, mock-slave, workflow-{job,cps,basic-steps,durable-task-step}; mock cloud with label `mock` created
    • 1293.v6c4d0ce54ee8

      If some of the optional dependencies of this plugin are not installed, then a simple build like

      node('mock') {
          git 'https://github.com/jglick/simple-maven-project-with-tests'
          withMaven {
              sh 'mvn verify'
          }
      }
      

      fails:

      java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
      	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
      	at jenkins.util.URLClassLoader2.findClass(URLClassLoader2.java:35)
      	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
      	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
      Caused: java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
      	at org.jenkinsci.plugins.pipeline.maven.dao.CustomTypePipelineMavenPluginDaoDecorator.shouldReportAgainWithExtensionAsType(CustomTypePipelineMavenPluginDaoDecorator.java:48)
      	at org.jenkinsci.plugins.pipeline.maven.dao.CustomTypePipelineMavenPluginDaoDecorator.recordGeneratedArtifact(CustomTypePipelineMavenPluginDaoDecorator.java:38)
      	at org.jenkinsci.plugins.pipeline.maven.dao.AbstractPipelineMavenPluginDaoDecorator.recordGeneratedArtifact(AbstractPipelineMavenPluginDaoDecorator.java:33)
      	at org.jenkinsci.plugins.pipeline.maven.dao.MonitoringPipelineMavenPluginDaoDecorator.lambda$recordGeneratedArtifact$2(MonitoringPipelineMavenPluginDaoDecorator.java:51)
      	at org.jenkinsci.plugins.pipeline.maven.dao.MonitoringPipelineMavenPluginDaoDecorator.executeMonitored(MonitoringPipelineMavenPluginDaoDecorator.java:155)
      	at org.jenkinsci.plugins.pipeline.maven.dao.MonitoringPipelineMavenPluginDaoDecorator.recordGeneratedArtifact(MonitoringPipelineMavenPluginDaoDecorator.java:51)
      	at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.recordGeneratedArtifacts(PipelineGraphPublisher.java:215)
      	at org.jenkinsci.plugins.pipeline.maven.publishers.PipelineGraphPublisher.process(PipelineGraphPublisher.java:94)
      	at org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor.processMavenSpyLogs(MavenSpyLogProcessor.java:153)
      	at org.jenkinsci.plugins.pipeline.maven.WithMavenStepExecution2$WithMavenStepExecutionCallBack.finished(WithMavenStepExecution2.java:1102)
      	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(GeneralNonBlockingStepExecution.java:140)
      	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      

      This seems to be because you are using commons-lang3 in various places without actually declaring a dep on the commons-lang3-api plugin. Code compiles because Maven picks it up via transitive deps from optional plugins, like junitchecks-api.

      Workaround (if you want to call it that): install the junit plugin and restart.

      Best to avoid usage of this library (it seems to be used just for a couple trivial methods from StringUtils that are easily replaced with Java Platform equivalents), but if you really want to use it, declare a direct dep. You can see this sort of warning from dependency:analyze though we do not currently enforce it in plugin builds.

      Either way, if you want to use optional dependencies, it is important to test whether the plugin actually behaves properly when they are not enabled. RealJenkinsRule.omitPlugins can even do this in automated tests.

            bguerin Benoit
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: