I am using job-dsl plugin to automate jenkins jobs creation. Below is my maven configuration.
<java.version>1.8</java.version>
<groovy.version>2.4.4</groovy.version>
<dsl.version>1.37</dsl.version>
<groovy.eclipse.compiler.version>2.9.101</groovy.eclipse.compiler.version>
<groovy.eclipse.batch.version>2.3.7-01</groovy.eclipse.batch.version>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy.eclipse.compiler.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy.eclipse.batch.version}</version>
</dependency>
</dependencies>
</plugin>
I am using jdk8 & groovy-all 2.4.4 ,groovy-eclipse-compiler & an uber jar is generated using shade plugin. To run my scripts, I added additional classpath (under process job-dsl/advanced-settings) as target/my-uber.jar.
When I run my tests locally everything works well but on Jenkins am getting following errors
java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for com.salesforce.dva.pipeline.generator.model.PkgType do not match. Expected -1 but got 2
at groovy.lang.MetaClassImpl.selectConstructorAndTransformArguments(MetaClassImpl.java:1413)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.selectConstructorAndTransformArguments(ScriptBytecodeAdapter.java:234)
I tried changing groovy versions (to older) & setting jdk 7 & 6 but all of them resulted in the same error.
How can I fix this issue ?
Jenkins uses Groovy 1.8.x, so the Job DSL plugin also uses Groovy 1.8.x. Currently it's 1.8.9. The update to Groovy 2.x is still pending, See JENKINS-21249. It's recommended to use Groovy 1.8 for any Job DSL project.
Since Groovy 2.3 is the first version that officially supports Java 8 (see Release notes for Groovy 2.3), it's recommended to use Java 7 for any Groovy 1.8 project.