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

JenkinsRule not working with Gradle JPI Plugin

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • gradle-jpi-plugin
    • None

      I'm updating the jenkinsVersion I rely on in my project https://github.com/jenkinsci/inedo-proget-plugin/tree/SecretManagement but are having problems with tests that use JenkinsRule.
       
      Up to jenkins version 2.63 it works fine, from 2.64 onwards I get:

      java.lang.AssertionError: D:\Work\gradle_user_home\caches\modules-2\files-2.1\org.jenkins-ci.main\jenkins-core\2.64\6766ac4d8dd4a6ca1920f5156bb10be656d4ded3\jenkins-core-2.64.jar is not in the expected location, and jenkins-war-*.war was not in D:\Work\Eclipse\workspace\inedo-proget-plugin\bin\main;
      D:\Work\Eclipse\workspace\inedo-proget-plugin\bin\test;
      D:\Work\gradle_user_home\caches\modules-2\files-2.1\org.concordion\cubano-httpeasy\0.3.5\f25d55eb0bc86ff10524bf91fa209be0e305ffb4\cubano-httpeasy-0.3.5.jar;
      ... 
      long list of jar files
      ...
      D:\Work\Eclipse\eclipse-oxygen\eclipse\configuration\org.eclipse.osgi\413\0\.cp;
      D:\Work\Eclipse\eclipse-oxygen\eclipse\configuration\org.eclipse.osgi\1168\0\.cp
       at org.jvnet.hudson.test.WarExploder.explode(WarExploder.java:119)
       at org.jvnet.hudson.test.WarExploder.<clinit>(WarExploder.java:68)
       at org.jvnet.hudson.test.JenkinsRule._createWebServer(JenkinsRule.java:748)
       at org.jvnet.hudson.test.JenkinsRule.createWebServer(JenkinsRule.java:718)
       at org.jvnet.hudson.test.JenkinsRule.newHudson(JenkinsRule.java:670)
       at org.jvnet.hudson.test.JenkinsRule.before(JenkinsRule.java:402)
       at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:595)
       at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
       at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.lang.Thread.run(Thread.java:745)

       
      My build.gradle file is
       

      plugins {
        id 'org.jenkins-ci.jpi' version '0.28.1'
      }
      
      apply plugin: 'java'
      
      sourceCompatibility = 1.8
      targetCompatibility = 1.8
      
      group = 'com.inedo.proget'
      version = '1.2'
      description = 'Inedo ProGet Plugin'
      
      ext {
       jenkinsVersion='2.64'
      }
      
      jenkinsPlugin {
          coreVersion = "$jenkinsVersion"
          displayName = 'Inedo ProGet Plugin.'
          shortName = 'inedo-proget'
          url = 'http://wiki.jenkins-ci.org/display/JENKINS/Inedo+ProGet+Plugin'
          gitHubUrl = 'https://github.com/jenkinsci/inedo-proget-plugin'
          developers {
              developer {
                  id 'andrew-sumner'
                  name 'Andrew Sumner'
                  email 'andrew.sumner@***.***'
              }
          }
      }
      
      repositories {
        maven { 
          url 'http://repo.jenkins-ci.org/public' } // prevent java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
       
          jcenter()
      }
      
      dependencies {
       compile 'org.concordion:cubano-httpeasy:0.3.5';
       
       testCompile 'com.jayway.jsonpath:json-path:2.4.0'
       testCompile 'junit:junit:4.12'
       testCompile 'org.mockito:mockito-core:2.28.2'
       testCompile 'org.jenkins-ci.main:jenkins-test-harness:2.55'
      }
      
      task wrapper(type: Wrapper) {
          gradleVersion = '4.7'
      }

       

      As an aside, do you know why I have to explicity add repo 'http://repo.jenkins-ci.org/public' rather than just use jcenter?

          [JENKINS-59373] JenkinsRule not working with Gradle JPI Plugin

          Daniel Beck added a comment -

          https://jenkins.io/changelog/#v2.64 (last entry) explains it – there's no longer a war-for-test.

          Daniel Beck added a comment - https://jenkins.io/changelog/#v2.64 (last entry) explains it – there's no longer a war-for-test.

          Andrew Sumner added a comment -

          That changelong leads to https://groups.google.com/forum/#!topic/job-dsl-plugin/oPjqGR6VTpU and https://github.com/jenkinsci/job-dsl-plugin/blob/ca99792f54e2f3a754e70a9a69e3c5f36c885db3/docs/Testing-DSL-Scripts.md which indicate that this can be fixed by adding testCompile "org.jenkins-ci.main:jenkins-war:${jenkinsVersion}".  

          I've tried this and it makes no difference: https://github.com/jenkinsci/inedo-proget-plugin/blob/master/build.gradle

          Andrew Sumner added a comment - That changelong leads to  https://groups.google.com/forum/#!topic/job-dsl-plugin/oPjqGR6VTpU and  https://github.com/jenkinsci/job-dsl-plugin/blob/ca99792f54e2f3a754e70a9a69e3c5f36c885db3/docs/Testing-DSL-Scripts.md which indicate that this can be fixed by adding testCompile "org.jenkins-ci.main:jenkins-war:${jenkinsVersion}".   I've tried this and it makes no difference: https://github.com/jenkinsci/inedo-proget-plugin/blob/master/build.gradle

          Steve Hill added a comment -

          Hi andrewsumner, thanks for the report!
           
          Is there a set of commands I can run to reproduce the error you're getting? After cloning your repo's master branch (commit 7988b3a76b8f1203f13d83e58e6edaec28902108), I'm able to run both ./gradlew check on the command line and com.inedo.proget.jenkins.PluginTests from IntelliJ. From the logs, it does appear to be starting and stopping the server as expected.

          Thanks danielbeck for the link to the changelog! We could potentially make this transition a little easier in the plugin, but this is the first time it's come up as an issue. The changelog is from 2017, so this change has been out for quite a while.

          As an aside, do you know why I have to explicity add repo 'http://repo.jenkins-ci.org/public' rather than just use jcenter?

          Yes, it's because most jenkins-specific dependencies and plugins are not published to jcenter. They're published to the maven repository at repo.jenkins-ci.org.

          Gradle Version

          I see you're running Gradle 4.7. Have you considered upgrading? This version is quite old (released 2018-04-18) and the next release due out is Gradle 6.0. There are many nice features introduced in Gradle 5.x and coming in 6.x. Ideally a future release of gradle-jpi-plugin will stop supporting the Gradle 4.x series.

          Steve Hill added a comment - Hi  andrewsumner , thanks for the report!   Is there a set of commands I can run to reproduce the error you're getting? After cloning your repo's master branch (commit 7988b3a76b8f1203f13d83e58e6edaec28902108), I'm able to run both  ./gradlew check on the command line and com.inedo.proget.jenkins.PluginTests from IntelliJ. From the logs, it does appear to be starting and stopping the server as expected. Thanks danielbeck for the link to the changelog! We could potentially make this transition a little easier in the plugin, but this is the first time it's come up as an issue. The changelog is from 2017, so this change has been out for quite a while. As an aside, do you know why I have to explicity add repo 'http://repo.jenkins-ci.org/public' rather than just use jcenter? Yes, it's because most jenkins-specific dependencies and plugins are not published to jcenter. They're published to the maven repository at repo.jenkins-ci.org. Gradle Version I see you're running Gradle 4.7. Have you considered upgrading? This version is quite old (released 2018-04-18) and the next release due out is Gradle 6.0. There are many nice features introduced in Gradle 5.x and coming in 6.x. Ideally a future release of gradle-jpi-plugin will stop supporting the Gradle 4.x series.

          Andrew Sumner added a comment -

          I tried again after rebooting PC and running via gradle and then eclipse, it worked fine.  Thanks and sorry for wasting your time.

          Andrew Sumner added a comment - I tried again after rebooting PC and running via gradle and then eclipse, it worked fine.  Thanks and sorry for wasting your time.

            lazlodeveloper Laszlo Dian
            andrewsumner Andrew Sumner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: