4

I am writing a groovy script and trying to download jenkins-core module using Grapes but I am not able to.

@Grapes([
    @Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.9')
])
import jenkins.model.Jenkins

It is giving me following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during conversion: Error grabbing Grapes -- [unresolved dependency: org.jenkins-ci.main#jenkins-core;2.9: not found]

java.lang.RuntimeException: Error grabbing Grapes -- [unresolved dependency: org.jenkins-ci.main#jenkins-core;2.9: not found]

I have tried other versions also but it didn't work. These version are available in maven repo. I would really appreciate if you could help me resolving the issue.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
LifeIsButifool
  • 129
  • 2
  • 12

1 Answers1

2

As jenkins-core is not available in maven central but in jenkins-ci maven repository, you need to add http://repo.jenkins-ci.org repository.

Grape

@GrabResolver(name='jenkins', root='http://repo.jenkins-ci.org/public/')
@Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.9')
import jenkins.model.Jenkins

Note: You need to be using groovy version 2.4.7 or higher to be able to grab jenkins-core due to this fixed groovy bug

Gradle

Add a new maven repository for jenkins-ci.org and the jenkins-core dependency

repositories {

    ...       

    maven {
        url 'http://repo.jenkins-ci.org/public/'
    }
}

dependencies {

    ... 

    compile group: 'org.jenkins-ci.main', name: 'jenkins-core', version: '2.9'
}
Gergely Toth
  • 6,638
  • 2
  • 38
  • 40
  • Updated the answer with build.gradle – Gergely Toth Aug 17 '16 at 05:01
  • I'm not using Gradle, I'm adding Groovy code to Maven using the Jenkins Pipeline plugin. I've added your Grape lines and I'm getting this error: `Error grabbing Grapes -- [unresolved dependency: org.jenkins-ci.main#jenkins-core;2.9: not found]` Any idea how to resolve the dependencies? – bsky Feb 15 '17 at 11:00