AOEpeople / gradle-jenkins-job-dsl-plugin

Plugin for easy management of Jenkins Job DSL scripts with Gradle
MIT License
25 stars 12 forks source link

JobScriptsSpec fails with "java.lang.VerifyError: (class: com/thoughtworks/xstream/core/util/SerializationMembers, method: getSerializablePersistentFields signature: (Ljava/lang/Class;)Ljava/util/Map;) Incompatible object argument for function call" #23

Open dresnick-sf opened 3 years ago

dresnick-sf commented 3 years ago

Using id 'com.aoe.jenkins-job-dsl' version '2.9.0'

Encountering this error after trying to upgrade Jenkins

 configurations.all {
   resolutionStrategy.dependencySubstitution {
-    substitute module("org.jenkins-ci.main:jenkins-war:2.121") because "Version we use" with module("org.jenkins-ci.main:jenkins-war:2.235.2")
+    substitute module("org.jenkins-ci.main:jenkins-war:2.121") because "Version we use" with module("org.jenkins-ci.main:jenkins-war:2.277.3")
     // this matches the Jenkins version defined in docker-services/jenkins-cd/Dockerfile
-    substitute module("org.jenkins-ci.main:jenkins-war:2.235.2")
+    substitute module("org.jenkins-ci.main:jenkins-war:2.277.3")
   }

It looks like this is caused by JENKINS-65341. This has a simple workaround which I have not tried.

The full error

Apr 28, 2021 4:19:04 PM jenkins.model.Jenkins <clinit>
SEVERE: Failed to load Jenkins.class
java.lang.VerifyError: (class: com/thoughtworks/xstream/core/util/SerializationMembers, method: getSerializablePersistentFields signature: (Ljava/lang/Class;)Ljava/util/Map;) Incompatible object argument for function call
    at hudson.util.RobustReflectionConverter.<init>(RobustReflectionConverter.java:106)
    at hudson.util.XStream2.setupConverters(XStream2.java:218)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:574)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:496)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:465)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:411)
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:378)
    at hudson.util.XStream2.<init>(XStream2.java:113)
    at jenkins.model.Jenkins.<clinit>(Jenkins.java:5439)
    at hudson.PluginManager.<clinit>(PluginManager.java:2227)
    at org.jvnet.hudson.test.JenkinsRule.<init>(JenkinsRule.java:333)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:239)
    at com.aoe.gradle.jenkinsjobdsl.JobScriptsSpec.$spock_initializeSharedFields(JobScriptsSpec.groovy:38)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:188)
    at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.doRunSharedInitializer(BaseSpecRunner.java:148)
    at org.spockframework.runtime.BaseSpecRunner$2.invoke(BaseSpecRunner.java:133)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
    at org.spockframework.runtime.BaseSpecRunner.runSharedInitializer(BaseSpecRunner.java:126)
    at org.spockframework.runtime.BaseSpecRunner.runSharedInitializer(BaseSpecRunner.java:121)
    at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:66)
    at org.spockframework.runtime.Sputnik.run(Sputnik.java:63)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.base/java.lang.Thread.run(Unknown Source)
amotl commented 2 years ago

Dear @carstenlenz, @dresnick-sf, @daspilker and @jamietanna,

firstly, I would like to thank you for conceiving and maintaining the excellent Job DSL plugin and Gradle Job DSL support plugin. What would Jenkins be without it!

Then, we wanted to report back that we are observing the same issue as outlined at JENKINS-65341 and reported by @dresnick-sf here. In order to be able to reproduce it without efforts, we created a repository at ^1. Maybe this can be a common ground for further investigations.

Unfortunately, we have not been able to successfully apply the workaround outlined within JENKINS-65341. Any hints on how to make that work would be greatly appreciated.

Thank you already for taking the time to look into this!

With kind regards, Andreas.

xsaero00 commented 2 years ago

I was able to get it to work with newest version of Jenkins by using io.spring.dependency-management plugin to exclude xstream module. I feel like there is a better way to do that without using additional plugin but this worked for me. build.gradle

plugins {
    id 'com.aoe.jenkins-job-dsl' version '2.9.0'
    id "io.spring.dependency-management" version "1.0.12.RELEASE"
}

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module("org.jenkins-ci.main:jenkins-war") because "Jenkins In Use" with module("org.jenkins-ci.main:jenkins-war:${jenkinsVersion}")
        substitute module("org.codehaus.groovy:groovy-all") because "The matching groovy version for the Jenkins" with module("org.codehaus.groovy:groovy-all:${groovyVersion}")
    }
}

dependencyManagement {
    dependencies {
        dependency("org.jenkins-ci.plugins:job-dsl-core:${jobDslVersion}") {
            exclude 'org.jvnet.hudson:xstream'
        }
    }
}

jobDsl {
    version = jobDslVersion
}

gradle.properties

jobDslVersion=1.80
jenkinsVersion=2.346.1
# Groovy version used in target Jenkins env:
# Run `println GroovySystem.version` in script console to get the version
groovyVersion=2.4.21
vlad-ivanov-name commented 2 years ago

@xsaero00 thanks a lot for the provided solution, it worked for me. Below is a snippet that does the same thing but for Maven:

        <dependency>
            <groupId>org.jenkins-ci.plugins</groupId>
            <artifactId>job-dsl-core</artifactId>
            <version>1.80</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jvnet.hudson</groupId>
                    <artifactId>xstream</artifactId>
                </exclusion>
            </exclusions>
        </dependency>