1

I'm fairly new to Groovy and I'm trying to wrap my head around Gradle. If I import the org.jvnet.hudson.plugins through Grapes it works perfectly and the dependency is resolved. But if I try to retrieve the dependency using Gradle the dependency is not resolved.

The package org.eclipse.hudson:hudson-core:3.2.1 works with both Gradle and Grape.

A dependency that is not resolved using Gradle

compile 'org.jvnet.hudson.plugins:checkstyle:3.42'

A dependency which is resolved using Grape

@Grab('org.jvnet.hudson.plugins:checkstyle:3.42')

A dependency which is resolved using Gradle

compile 'org.eclipse.hudson:hudson-core:3.2.1'

Error during Gradle build

line 3, column 1.
   import hudson.plugins.checkstyle.CheckStyleResultAction;
   ^

The build.gradle

apply plugin: 'groovy'

repositories {
    mavenCentral()

    maven {
        url "http://repo.jenkins-ci.org/releases/"
    }
}

configurations {
    ivy
}

sourceSets {
    main {
        groovy {
            srcDirs = ['src/']
        }
    }

    test {
        groovy {
            srcDirs = ['test/']
        }
    }
}

dependencies {

    compile 'org.codehaus.groovy:groovy-all:2.4.11'

    compile "org.apache.ivy:ivy:2.4.0"
    ivy "org.apache.ivy:ivy:2.3.0"

    // Works
    compile 'org.eclipse.hudson:hudson-core:3.2.1'

    // Does not work
    compile 'org.jvnet.hudson.plugins:checkstyle:3.42'
}


tasks.withType(GroovyCompile) {
    groovyClasspath += configurations.ivy
}
M. Justin
  • 14,487
  • 7
  • 91
  • 130
user634545
  • 9,099
  • 5
  • 29
  • 40

1 Answers1

2

You're probably not actually downloading the jar you think you are. Looks like the default artifact that comes back from the org.jvnet.hudson.plugins:checkstyle:3.42 dependency is actually a file named checkstyle-3.42.hpi.

To get the jar which contains the classes instead, use:

compile group: 'org.jvnet.hudson.plugins', name: 'checkstyle', version:'3.42', ext: 'jar'

Then that class will be found on your classpath (and you'll be on to locating the next missing dependency).

Tom Tresansky
  • 19,364
  • 17
  • 93
  • 129
  • compile group: 'org.jvnet.hudson.plugins', name: 'checkstyle', version:'3.42', ext: 'jar' worked. The key was "ext: jar". What does hpi stand for, and why does it fallback to using hpi instead of jar? Btw, why did you use ivy instead of compile? Thanks :) – user634545 Jan 11 '18 at 09:21
  • The ivy was a mistake, I've changed it back to compile. Don't know what a hpi file is, haven't encountered one before. – Tom Tresansky Jan 11 '18 at 13:27