Gradle : How to ignore failure to resolve a specific dependency

3.1k Views Asked by At
dependencies {
    test "com.test:testA:1.0@jar"
    test "com.test:testB:1.0@jar"
}


task('collectArtifacts', type: Copy) {
     from project.configurations.test
     into 'artifacts/'
}

Assuming the artifact testA is missing and testB is available

When I use ./gradlew collectArtifacts it obviously complains saying "> Could not find com.test:testA:1.0".

How can I ask gradle to:

  • If testA is available all is good, gradle downloads both testA and testB
  • If testA is not available I want gradle to ignore resolution failure for testA dependency and move ahead to download testB.
2

There are 2 best solutions below

2
majk On BEST ANSWER

Perhaps a bit counter-intuitively, you can use getResolvedConfiguration() in combination with getLenientConfiguration() to retrieve a configuration that does not fail if some of the references are not resolvable.

task('collectArtifacts', type: Copy) {
     from project.configurations.test.resolvedConfiguration.lenientConfiguration.getFiles(Specs.satisfyAll())
     into 'artifacts/'
}

See documentation.

1
Christopher Z On

You could try the following. Not sure what exactly test is, so I'm assuming it is a typo for testCompile.

task('collectArtifacts', type: Copy) {
    from project.configurations.testCompile.findAll { it.exists() }
    into 'artifacts/'
}