How to access a prior verison of the artifact produced by a project


(BJ Hargrave) #1

I have a task which needs to access the prior version of the artifact built by a project to use as a baseline for the currently building version of the artifact. The prior versions of the artifact are in a configured repository.

Doing the obvious:

configurations {
  prior
  prior.transitive = false
}

dependencies {
  prior "${group}:${project.name}:(,${project.version}["
}

Does not work as the configuration holds the project’s output (the currently built artifact) and not a prior version.

$ gradle dependencies --configuration prior prior

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

prior
\--- test:baselinetask1:(,1.1.0[ -> project : (*)

(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.

> Task :prior
prior: /Users/hargrave/tmp/gradle-dep/prior/build/libs/baselinetask1-1.1.0.jar

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed

If I delete the dependencies section and add a defaultDependencies closure:

configurations {
  prior
  prior.transitive = false
  prior.defaultDependencies { deps ->
    println "prior: defaultDependencies ${group}:${project.name}:(,${project.version}["
    Dependency priorDep = dependencies.create('group': group, 'name': project.name, 'version': "(,${project.version}[") {
      force = true
      transitive = false
    }
    println "priorDep: ${priorDep}"
    deps.add(priorDep)
  }
}

task prior {
  doFirst {
    println "prior: ${configurations.prior.asPath}"
  }
}

Then it works as desired on versions of Gradle prior to 4.8:

$ ./gradlew dependencies --configuration prior prior

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

prior
prior: defaultDependencies test:baselinetask1:(,1.1.0[
priorDep: DefaultExternalModuleDependency{group='test', name='baselinetask1', version='(,1.1.0[', configuration='default'}
\--- test:baselinetask1:(,1.1.0[ -> 1.0.0

A web-based, searchable dependency report is available by adding the --scan option.

> Task :prior
prior: /Users/hargrave/tmp/gradle-dep/prior/repodir/test/baselinetask1/1.0.0/baselinetask1-1.0.0.jar

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed

But on Gradle 4.8 or later, the defaultDependencies section results in the project’s artifact instead of the prior version as desired.

$ gradle dependencies --configuration prior prior

> Task :dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

prior
prior: defaultDependencies test:baselinetask1:(,1.1.0[
priorDep: DefaultExternalModuleDependency{group='test', name='baselinetask1', version='(,1.1.0[', configuration='default'}
\--- test:baselinetask1:(,1.1.0[ -> project : (*)

(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.

> Task :prior
prior: /Users/hargrave/tmp/gradle-dep/prior/build/libs/baselinetask1-1.1.0.jar

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed

What is the proper way to set up a configuration to access a prior version of the artifact built by a project?

Thanks