Gradle always resolves my local artifact as a dependency even when the version is wrong

I have a Gradle script that uses a previously released version of its own artifact as a dependency (one of my tasks runs a diff process between the version I just built and the last release). For some reason, even when I specify the version that’s on Maven Central, Gradle resolves the dependency as being the local artifact that I just built.

Script (snippet):

group = 'com.foo'
version = '0.3.5'
  configurations {
 bar
}
  dependencies {
 bar group: 'com.foo', name: 'bar', version: '0.3.4', transitive: false
}
  task checkDependency {
 configurations.bar.each { println it }
}

‘D:\myProject>gradle checkDependency’

Output:

D:\myProject\build\libs\bar-0.3.5.jar

It will resolve this way even if the 0.3.5 jar (or the build directory entirely) doesn’t exist! If I change the buildscript’s group to have a typo in it such as “com.ffoo” thus giving the artifact a different namespace from what’s in the dependency, then it properly resolves the 0.3.4 version in my local cache downloaded from Maven Central. Why doesn’t the same work for the version?

At first I thought this was an issue with pulling the latest integration, as I initially had “latest.integration” as the version for my dependency, but I have no idea why this would be happening when the version is now hard coded.

The issue is, that there is a conflict between the thirdparty dependency you declare and the id of your current project. in your dependency graph you now have com.foo:bar:0.3.5 -> com.foo.bar:0.3.4. This is resolved by gradle to the output of your project.

Is there any way to isolate this the dependency from the current project?

The operation to retrieve the “latest.release” of the current project/module is to be able to baseline it.

Barring that, is it possible to obtain the URL of the dependency to be able to retrieve it manually?

Is there any way to isolate this dependency from the current project?

The operation to retrieve the “latest.release” of the current project/module is to be able to baseline new version.

Barring that, is it possible to obtain the URL of the dependency to be able to retrieve it manually?

Thanks for your reply, Rene. I’m at a loss for what I can do as a solution, though. Does this mean it’s impossible in Gradle for a script to use a previous version of its own artifact as a dependency?

Just force the dependency.

dependencies {

bar(‘com.foo:bar:0.3.4’) {

force true

transitive false

}

}

Awesome! This worked perfectly.

Thank you Mark!