Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle : How to ignore failure to resolve a specific dependency

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.
like image 591
xask Avatar asked Feb 07 '23 15:02

xask


1 Answers

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.

like image 96
majk Avatar answered Feb 15 '23 09:02

majk