I have the following build.gradle
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'java'
repositories {
mavenCentral()
maven {
url 'https://repo.jenkins-ci.org/releases'
}
maven {
url 'https://repo.jenkins-ci.org/public'
}
}
sourceSets {
main {
groovy {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
dependencies {
compile group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.76'
compile group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.13'
compile 'com.cloudbees:groovy-cps:1.14'
compile 'org.connectbot.jbcrypt:jbcrypt:1.0.0'
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
compile 'org.codehaus.groovy:groovy-all:2.4.12'
testCompile 'junit:junit:4.12'
}
When I run "gradle build" I get the following error:
> Task :compileGroovy FAILED
startup failed:
/home/user/myproject/SomeClass.groovy: 26: unable to resolve class org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
@ line 26, column 11.
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException flowInterruptedException) {
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed
It's as if it does not see "org.jenkinsci.plugins.workflow.steps.FlowInterruptedException" but I added workflow-step-api and it should find it.
What am I doing wrong? How to fix?
Thank you
The 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.13'
dependency has a POM that has this in it (taken from here):
<packaging>hpi</packaging>
The dependency that Gradle retrieves is the hpi
artifact, not the jar
one when you point at this dependency. This can be shown with a task like the following:
tasks.create('showDependencies') {
doFirst {
final config = configurations.getByName(sourceSets.getByName('main').compileClasspathConfigurationName)
config.resolvedConfiguration.resolvedArtifacts.findAll { it.moduleVersion.id.group.contains('jenkins') }.each {
println("Resolved dependency: id=${it.id}, extension=${it.extension}, classifier=${it.classifier}")
}
}
}
The output:
> Task :showDependencies
Resolved dependency: id=jenkins-core.jar (org.jenkins-ci.main:jenkins-core:2.76), extension=jar, classifier=null
Resolved dependency: id=workflow-step-api.hpi (org.jenkins-ci.plugins.workflow:workflow-step-api:2.13), extension=hpi, classifier=null
Resolved dependency: id=cli.jar (org.jenkins-ci.main:cli:2.76), extension=jar, classifier=null
Resolved dependency: id=trilead-ssh2.jar (org.jenkins-ci:trilead-ssh2:build-217-jenkins-11), extension=jar, classifier=null
Resolved dependency: id=icon-set.jar (org.jenkins-ci.plugins.icon-shim:icon-set:1.0.5), extension=jar, classifier=null
Resolved dependency: id=remoting.jar (org.jenkins-ci.main:remoting:3.11), extension=jar, classifier=null
Resolved dependency: id=version-number.jar (org.jenkins-ci:version-number:1.4), extension=jar, classifier=null
Resolved dependency: id=crypto-util.jar (org.jenkins-ci:crypto-util:1.1), extension=jar, classifier=null
Resolved dependency: id=bytecode-compatibility-transformer.jar (org.jenkins-ci:bytecode-compatibility-transformer:1.8), extension=jar, classifier=null
Resolved dependency: id=structs.hpi (org.jenkins-ci.plugins:structs:1.5), extension=hpi, classifier=null
Resolved dependency: id=symbol-annotation.jar (org.jenkins-ci:symbol-annotation:1.5), extension=jar, classifier=null
Resolved dependency: id=annotation-indexer.jar (org.jenkins-ci:annotation-indexer:1.12), extension=jar, classifier=null
Resolved dependency: id=task-reactor.jar (org.jenkins-ci:task-reactor:1.4), extension=jar, classifier=null
Resolved dependency: id=commons-jelly.jar (org.jenkins-ci:commons-jelly:1.1-jenkins-20120928), extension=jar, classifier=null
Resolved dependency: id=commons-jexl.jar (org.jenkins-ci:commons-jexl:1.1-jenkins-20111212), extension=jar, classifier=null
Resolved dependency: id=memory-monitor.jar (org.jenkins-ci:memory-monitor:1.9), extension=jar, classifier=null
Resolved dependency: id=jmdns.jar (org.jenkins-ci:jmdns:3.4.0-jenkins-3), extension=jar, classifier=null
Resolved dependency: id=constant-pool-scanner.jar (org.jenkins-ci:constant-pool-scanner:1.2), extension=jar, classifier=null
Resolved dependency: id=dom4j.jar (org.jenkins-ci.dom4j:dom4j:1.6.1-jenkins-4), extension=jar, classifier=null
There are several ways to use Gradle's dependency management features to better handle dependencies. One possible way to change the dependency would be to add an artifact dependency with the extension. This may not solve your exact use case depending on how you want your dependencies to end up, but can hopefully point you in a direction:
compile(group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.13') {
artifact {
name = 'workflow-step-api'
type = 'jar'
}
}
As a side note, in the Jenkins plugin ecosystem, the Jenkins Maven HPI Plugin and Jenkins Plugin Parent POM work together to do dependency management so you don't run into issues like this.
Apparently I needed to add ext jar. Here is my build file
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'java'
repositories {
mavenCentral()
maven {
url 'https://repo.jenkins-ci.org/releases'
}
maven {
url 'https://repo.jenkins-ci.org/public'
}
}
sourceSets {
main {
groovy {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
dependencies {
compile group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.76'
compile group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-step-api', version: '2.13', ext: 'jar'
compile 'com.cloudbees:groovy-cps:1.14'
compile 'org.codehaus.groovy:groovy-all:2.4.8'
compileOnly 'javax.servlet:javax.servlet-api:3.1.0'
testCompile 'junit:junit:4.12'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With