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

Getting java.lang.NoClassDefFoundError: hudson/matrix/MatrixRun error attempting to run a unit test

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • gradle-jpi-plugin
    • None
    • dependencies {
          classpath 'org.jenkins-ci.tools:gradle-jpi-plugin:0.10.2'
      }

      I get the following error when trying to run a unit test. Example code is below.

      I was able to get past this error by including dependancy testCompile 'org.jvnet.hudson.main:hudson-core:1.159' but that then said other classes where missing. This doesn't see the correct path to go down anyway.

      Error

       
      java.lang.NoClassDefFoundError: hudson/matrix/MatrixRun
      	at com.inedo.TriggerBuildStepTest.<init>(TriggerBuildStepTest.java:13)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      ...
      Caused by: java.lang.ClassNotFoundException: hudson.matrix.MatrixRun
      	at java.net.URLClassLoader$1.run(Unknown Source)
      	at java.net.URLClassLoader$1.run(Unknown Source)
      	at java.security.AccessController.doPrivileged(Native Method)
      	at java.net.URLClassLoader.findClass(Unknown Source)
      	at java.lang.ClassLoader.loadClass(Unknown Source)
      	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      	at java.lang.ClassLoader.loadClass(Unknown Source)
      	... 23 more
      

      Code Example

      package test.example;
      
      import static org.junit.Assert.*;
      import org.jvnet.hudson.test.JenkinsRule;
      import org.apache.commons.io.FileUtils;
      import hudson.model.*;
      import hudson.tasks.Shell;
      import org.junit.Test;
      import org.junit.Rule;
      
      public class TriggerBuildStepTest {
        @Rule 
        public JenkinsRule j = new JenkinsRule();
        
        @Test 
        public void first() throws Exception {
      
          FreeStyleProject project = j.createFreeStyleProject();
          project.getBuildersList().add(new Shell("echo hello"));
          FreeStyleBuild build = project.scheduleBuild2(0).get();
          System.out.println(build.getDisplayName() + " completed");
          
          // TODO: change this to use HtmlUnit
          String s = FileUtils.readFileToString(build.getLogFile());
          assertTrue(s.contains("+ echo hello"));
        }
      }
      

          [JENKINS-27826] Getting java.lang.NoClassDefFoundError: hudson/matrix/MatrixRun error attempting to run a unit test

          Which coreVersion did you set in the build file? Only core versions 1.420 or later are supported, so adding a dependency to an ancient core version is not helping.

          As of Jenkins 1.561 the Matrix project has been moved to a plugin outside of Jenkins core, so you might need to add a dependency to that plugin.
          https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Project+Plugin

          Daniel Spilker added a comment - Which coreVersion did you set in the build file? Only core versions 1.420 or later are supported, so adding a dependency to an ancient core version is not helping. As of Jenkins 1.561 the Matrix project has been moved to a plugin outside of Jenkins core, so you might need to add a dependency to that plugin. https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Project+Plugin

          I confirm that adding the matrix-project fixes the problem:

          dependencies {
             ...
             jenkinsPlugins 'org.jenkins-ci.plugins:matrix-project:1.4@jar'
             ...
          }
          

          Damien Coraboeuf added a comment - I confirm that adding the matrix-project fixes the problem: dependencies { ... jenkinsPlugins 'org.jenkins-ci.plugins:matrix-project:1.4@jar' ... }

          Andrew Sumner added a comment -

          That seems to have fixed it, although I ended up adding it as jenkinsTest 'org.jenkins-ci.plugins:matrix-project:1.4@jar'.

          I'm now getting a huge amount of warnings in in the console output which I can only assume means something isn't quite right (although as this is my first plugin I've got nothing to compare against):

          WARNING: Failed to load hudson.matrix.MatrixProject
          java.lang.NoClassDefFoundError: hudson/tasks/test/AggregatedTestResultAction
          ...
          WARNING: Failed to scout hudson.matrix.FilterScript$ImpliesWhitelist
          java.lang.InstantiationException: java.lang.NoClassDefFoundError: org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/ProxyWhitelist
          ...

          My project is https://github.com/andrew-sumner/buildmaster-plugin/

          Andrew Sumner added a comment - That seems to have fixed it, although I ended up adding it as jenkinsTest 'org.jenkins-ci.plugins:matrix-project:1.4@jar'. I'm now getting a huge amount of warnings in in the console output which I can only assume means something isn't quite right (although as this is my first plugin I've got nothing to compare against): WARNING: Failed to load hudson.matrix.MatrixProject java.lang.NoClassDefFoundError: hudson/tasks/test/AggregatedTestResultAction ... WARNING: Failed to scout hudson.matrix.FilterScript$ImpliesWhitelist java.lang.InstantiationException: java.lang.NoClassDefFoundError: org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/ProxyWhitelist ... My project is https://github.com/andrew-sumner/buildmaster-plugin/

          Daniel Beck added a comment -

          java.lang.NoClassDefFoundError: hudson/tasks/test/AggregatedTestResultAction

          JUnit plugin was extracted from core in 1.577, so is not an explicit dependency of Matrix Project plugin, even though it's used by that.

          java.lang.InstantiationException: java.lang.NoClassDefFoundError: org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/ProxyWhitelist

          That's Script Security plugin, but I'm not sure how this gets involved. It only became a dependency of Matrix Project plugin in 1.2.1 and 1.4.1, and isn't in 1.4.

          Daniel Beck added a comment - java.lang.NoClassDefFoundError: hudson/tasks/test/AggregatedTestResultAction JUnit plugin was extracted from core in 1.577, so is not an explicit dependency of Matrix Project plugin, even though it's used by that. java.lang.InstantiationException: java.lang.NoClassDefFoundError: org/jenkinsci/plugins/scriptsecurity/sandbox/whitelists/ProxyWhitelist That's Script Security plugin, but I'm not sure how this gets involved. It only became a dependency of Matrix Project plugin in 1.2.1 and 1.4.1, and isn't in 1.4.

          @Andrew: Your repo does not reproduce the problem. Can you push a branch which shows the problem?

          Daniel Spilker added a comment - @Andrew: Your repo does not reproduce the problem. Can you push a branch which shows the problem?

          Andrew Sumner added a comment -

          I'm happy with adding the matrix project dependancy

          Andrew Sumner added a comment - I'm happy with adding the matrix project dependancy

          Alex Java added a comment -

          if you only need that plugin in tests, then probably

          jenkinsTest 'org.jenkins-ci.plugins:matrix-project:1.4@jar'

          is better than

          jenkinsPlugins 'org.jenkins-ci.plugins:matrix-project:1.4@jar'

          ?

          Alex Java added a comment - if you only need that plugin in tests, then probably jenkinsTest 'org.jenkins-ci.plugins:matrix-project:1.4@jar' is better than jenkinsPlugins 'org.jenkins-ci.plugins:matrix-project:1.4@jar' ?

            daspilker Daniel Spilker
            andrewsumner Andrew Sumner
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: