Groovy Plugin + Dependency with Classifier seems to break resolution

It seems that applying the Groovy plugin to a project which has a dependency with a classifier somehow breaks dependency resolution.

Consider this simple example buildscript:

apply plugin: 'java'
apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy:2.4.4:grooid'
}

If a build is attempted with this buildscript (and an empty Groovy source file to trigger the compilation) something quite strange happens:

:clean UP-TO-DATE
:compileJava UP-TO-DATE
:compileGroovy
Download https://repo1.maven.org/maven2/org/codehaus/groovy/groovy/2.4.4/groovy-2.4.4-grooid.jar

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration 'detachedConfiguration1'.
> Could not find org.codehaus.groovy:groovy:2.4.4-grooid.
  Searched in the following locations:
      https://repo1.maven.org/maven2/org/codehaus/groovy/groovy/2.4.4-grooid/groovy-2.4.4-grooid.pom
      https://repo1.maven.org/maven2/org/codehaus/groovy/groovy/2.4.4-grooid/groovy-2.4.4-grooid.jar
  Required by:
      com.example:GradleDepsProblem:1.0-SNAPSHOT
> Could not find org.codehaus.groovy:groovy-ant:2.4.4-grooid.
  Searched in the following locations:
      https://repo1.maven.org/maven2/org/codehaus/groovy/groovy-ant/2.4.4-grooid/groovy-ant-2.4.4-grooid.pom
      https://repo1.maven.org/maven2/org/codehaus/groovy/groovy-ant/2.4.4-grooid/groovy-ant-2.4.4-grooid.jar
  Required by:
      com.example:GradleDepsProblem:1.0-SNAPSHOT

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.031 secs

The first time dependency resolution is attempted it succeeds.

Download https://repo1.maven.org/maven2/org/codehaus/groovy/groovy/2.4.4/groovy-2.4.4-grooid.jar

That URL is correct, the download succeeds, and the JAR ends up in the Gradle caches when the download is complete.

What happens next is Gradle then attempts to resolve that same dependency again, however this time it gets the URL wrong, and is now treating the classifier as part of the version, which obviously fails. It also says it was the configuration ‘detachedConfiguration1’ for which it could not resolve the dependencies, but I haven’t created a detached configuration (or any additional configurations) and I’m only applying core language plugins.

Is there something I’ve missed here or is this looking like a bug?

I think you’ll need to use the more verbose map dependency notation. Eg:

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.4', classifier: 'grooid'
}

More info here

Sorry, should have mentioned that I have already tried that. Same result, unfortunately.

Looks like you’ve found a bug

It seems that somehow the classifier is being bundled together with the version during artifact resolution.

The following works fine for me with Gradle 2.10. What version are you using that produces the issue above?

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.4', classifier: 'grooid'
}

task copyLibs(type: Copy) {
    from configurations.compile
    into "$buildDir/libs"
}

Originally 2.9, but I’ve tried 2.10 this morning, as well as with the extra task which works as far as it copies the JAR into the build directory but the compileGroovy task is still failing for the same reason.

I’ve also tried not using the Maven co-ordinates at all, copying the JAR into the project directory, and using files() to declare the dependency but the failure is exactly the same.

Edit I tried renaming the file to take the classifier out of the filename, so my dependency block then looked like:

dependencies {
    compile files('lib/groovy-2.4.4.jar')
}

The build passed, but Gradle went to Maven Central and downloaded the non-classified version of the library.

:clean UP-TO-DATE
:compileJava UP-TO-DATE
:compileGroovy
Download https://repo1.maven.org/maven2/org/codehaus/groovy/groovy/2.4.4/groovy-2.4.4.jar
:processResources UP-TO-DATE
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Thanks for clarifying. That definitely looks like a bug. I raised GRADLE-3377.

I suspect that the regex in this file is the culprit which seems to reverse engineer the dependency notation from the filename.

The regex incorrectly calculates the version as 2.4.4-grooid for groovy-2.4.4-grooid.jar

@Adam_Pounder, since you are clearly trying to write an Android library, is there a reason you aren’t using the ‘com.android.library’ plugin?