3

I have a small groovy script that I want to edit and I have issues with the dependency management in Groovy. I am new to groovy and sorry in advance if this question is kinda studip / easy to answer. I use IntelliJ as IDEA.

@Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.167', scope='provided')
//import jenkins...

def call()
{
    Jenkins.instance.getItemByFullName(currentBuild.fullProjectName).getBuilds().each{ build ->

        if (currentBuild.number > build.number && exec != null)
        {
           build.rawBuild.doKill()
        }
    }
}

I try to use the jenkins-core dependency to get the autocomple of the code, documentation etc. etc. for the code but it simply does not work. I also tried the maven dependency in the pom it does work neither.

So now to my question: How do I import the dependency of Jenkins correctly in Groovy?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Michael Kemmerzell
  • 4,802
  • 4
  • 27
  • 43

1 Answers1

2

You can get this dependency from jenkins-ci maven repo:

@GrabResolver(name='jenkins', root='http://repo.jenkins-ci.org/public/')
@Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.167')
Evgeny Smirnov
  • 2,886
  • 1
  • 12
  • 22
  • I get the following error. Findbugs in the release maybe? @Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.9'): 0 jars Error grabbing Grapes -- [download failed: com.google.code.findbugs#jsr305;2.0.1!jsr305.jar] WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 – Michael Kemmerzell Mar 06 '19 at 17:33
  • I am using Java 11 and Groovy 3.0.0-alpha4 – Michael Kemmerzell Mar 06 '19 at 18:01
  • Findbugs hasn't been updated in a few years. Looks like it doesn't work on JDK 11 – Evgeny Smirnov Mar 07 '19 at 07:58
  • Unfortunately I am still not able to get a working setup. Do you know which Java JDK works with the jenkins-ci maven repo? – Michael Kemmerzell Mar 09 '19 at 12:41
  • JDK 8. Here you can find more detailed info: https://jenkins.io/doc/administration/requirements/java/ – Evgeny Smirnov Mar 09 '19 at 20:45
  • It finally worked, thanks god! I had to delete the .groovy and .m2 folder and do the Grab again. Thanks for your help! – Michael Kemmerzell Mar 10 '19 at 17:56