user1644873
user1644873

Reputation: 1231

Gradle build succeeds even though dependencies can't be downloaded

We are new to Gradle and dependency resolution. I am in the process of creating pom.xml files for all our internally-generated artifacts and want to set up a job in our Jenkins server to verify the dependencies are properly defined and not conflicting (i.e. LibA requires x-1.0.jar, LibB requires x-1.1.jar, and AppY requires both LibA and LibB).

As such, I've set up a dummy project in SVN that simply includes a bunch of our internal artifacts as dependencies. Following TTD, I intentionally included some errors in the declarations (i.e. group and name, but not version). Sure enough, those dependencies can't be found.

But when I run this build with gradle (i.e. gradle dependencies) it includes all the failure messages but still says the build succeeded! Not good!

How can I, using Gradle/Jenkins, set up an automated job that will verify all dependencies are found?

Upvotes: 1

Views: 1144

Answers (2)

Peter Niederwieser
Peter Niederwieser

Reputation: 123920

There is no built-in task that resolves all dependencies and fails if a dependency isn't found. (IDE tasks are graceful in case of missing dependencies.) But you can easily write your own:

task resolveDependencies { 
    doLast { 
        configurations.all { it.resolve() } 
    }
}

Upvotes: 4

Marcin Zajączkowski
Marcin Zajączkowski

Reputation: 4126

gradle dependencies by design displays Gradle project dependencies reporting (if applicable) if given dependency cannot be resolved (a red text FAILED next to an unresolved dependency). To get an error use some task that depends on resolving dependencies for given configuration(s) like gradle check.

Updated. Gradle is smart in determining if given tasks are required to be executed. Therefor in case there is no source files to compile (compilation requires dependent classes/JARs to be resolved) gradle check can notice that executing compileJava/compileTestJava tasks is not needed (tasks are skipped as up-to-date). You can force it by adding any Java source file into src/main/test (tests requires also production dependencies (from compile configuration)).

This is just a workaround, there is probably a better way to do that (and I hope someone else will present it here).

Upvotes: 0

Related Questions