Did the DependencyHandler change in gradle 2.0?

I am explicitly adding the dependency artifact like the example below but it is ignoring the artifact all together. The example is straight from the DependencyHandler documentation and what I am doing is something similar. This works in 1.12 but when I upgrade to 2.0 it ignores the artifact closure.

apply plugin: 'java' //so that I can declare 'compile' dependencies
  dependencies {
  //configuring dependency to specific configuration of the module
  compile configuration: 'someConf', group: 'org.someOrg', name: 'someModule', version: '1.0'
    //configuring dependency on 'someLib' module
  compile(group: 'org.myorg', name: 'someLib', version:'1.0') {
    //explicitly adding the dependency artifact:
    artifact {
      //useful when some artifact properties unconventional
      name = 'someArtifact' //artifact name different than module name
      extension = 'someExt'
      type = 'someType'
      classifier = 'someClassifier'
    }
  }
}

Hi,

I can’t observe a difference using this script and 2.0 and 1.12. Would you mind providing some instructions we can follow to observe the difference?

Ok…here is a basic HelloWorld gradle project with one dependencies…

apply plugin: 'java'
  sourceCompatibility = 1.5
version = '1.0'
  def artifactory_contextUrl = hasProperty('artifactory_contextUrl') ?
        artifactory_contextUrl :
        defaultArtifactoryContextUrl
  repositories {
    maven {
        url "${artifactory_contextUrl}/public"
    }
    ivy {
        url "${artifactory_contextUrl}/prerelease"
        layout "pattern", {
            artifact "[organisation]/[module]/[revision]/[type]/[artifact]-[revision](-[classifier]).[ext]"
        }
    }
    ivy {
        url "${artifactory_contextUrl}/external"
        layout "pattern", {
            artifact "[organisation]/[module]/[revision]/[type]/[artifact]-[revision](-[classifier]).[ext]"
        }
    }
    ivy {
        url "${artifactory_contextUrl}/repo1-cache"
        layout "pattern", {
            artifact "[organisation]/[module]/[revision]/[type]/[artifact]-[revision](-[classifier]).[ext]"
            artifact "[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"
            m2compatible = true
        }
    }
}
  dependencies {
    compile (group: 'com.example', name: 'mytools', version: '3535') {
        // explicitly adding the dependency artifact
        // artifact name is different than module name
        artifact {
            name = 'Mytools'
            extension = 'jar'
            type = 'jar'
        }
    }
}

Here is the build output using gradle version 1.12

C:\Users\jmessmer\IdeaProjects\gradleDependencyHandlerTest>which gradle
C:\Program Files\gradle\gradle-1.12\bin\gradle
  C:\Users\jmessmer\IdeaProjects\gradleDependencyHandlerTest>gradle build
:compileJava
                                                                     Download http://myArtifactoryURL.com:8081/artifactory/prerelease/com.example/mytools/3535/jar/Mytools-3535.jar
:compileJava UP-TO-DATE
                                :processResources UP-TO-DATE
     :classes UP-TO-DATE
      :jar UP-TO-DATE
      :assemble UP-TO-DATE
      :compileTestJava UP-TO-DATE
      :processTestResources UP-TO-DATE
      :testClasses UP-TO-DATE
      :test UP-TO-DATE
      :check UP-TO-DATE
      :build UP-TO-DATE
                       BUILD SUCCESSFUL
                 Total time: 3.052 secs

Here is the build output when I try do use gradle version 2.0:

C:\Users\jmessmer\IdeaProjects\gradleDependencyHandlerTest>which gradle
C:\Program Files\gradle\gradle-2.0\bin\gradle
  C:\Users\jmessmer\IdeaProjects\gradleDependencyHandlerTest>gradle build
:compileJava
                                                                                    FAILURE: Build failed with an exception.
               * What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not find com.example:mytools:3535
  Searched in the following locations:
      http://myArtifactoryURL.com:8081/artifactory/public/com/example/mytools/3535/mytools.3535.pom
      http://myArtifactoryURL.com:8081/artifactory/public/com/example/mytools/3535/mytools-3535.jar
    http://myArtifactoryURL.com:8081/artifactory/prerelease/com.example/mytools/3535/jar/mytools-3535.jar
      http://myArtifactoryURL.com:8081/artifactory/external/com.example/mytools/3535/ivy/ivy-3535.xml
      http://myArtifactoryURL.com:8081/artifactory/external/com.example/mytools/3535/jar/mytools-3535.jar
      http://myArtifactoryURL.com:8081/artifactory/repo1-cache/com/example/mytools/3535/ivy/ivy-3535.xml
      http://myArtifactoryURL.com:8081/artifactory/repo1-cache/com/example/mytools/3535/ivy-3535.xml
      http://myArtifactoryURL.com:8081/artifactory/repo1-cache/com/example/mytools/3535/jar/mytools-3535.jar
      http://myArtifactoryURL.com:8081/artifactory/repo1-cache/com/example/mytools/3535/mytools-3535.jar
  Required by:
      :gradleDependencyHandlerTest:1.0
               * 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: 7.425 secs
               C:\Users\jmessmer\IdeaProjects\gradleDependencyHandlerTest>

As you can see, my artifact has a different nomenclature than the module name…I am not sure if I need to do something different and how when I go to gradle 2.0

Thanks, Jay

Is this exactly the output you’re seeing? There seems to be something missing from the Gradle 2.0 output.

Can you further simplify this by: 1) Remove all repository declarations except for the ‘prerelease’ one 2) Add a simple task that does nothing more than resolve the configuration:

task fetch(type: Copy) {
    from configurations.compile
    into "build/fetch"
}
  1. Post the output of ‘gradle --refresh-dependencies fetch’ for Gradle 1.12 and Gradle 2.0. If you can grab the debug output and make it available via Gist that would be even better.

Actually, nevermind. I can confirm this is a regression in dependency resolution in Gradle 2.0. The issue occurs when there is no ivy.xml for a module, and the artifact name does not match the module name.

I’ve raised GRADLE-3118 to track this issue.

The tricky thing is that it looks like this has been already fixed in master, even though there’s been no corresponding bug report. Can you try a recent nightly build (http://gradle.org/nightly) and see if it fixes your problem?

The nightly worked…I used gradle-2.1-20140706220021 nightly

Great - thanks for letting us know.