Сбой сборки Gradle, когда зависимости недоступны - PullRequest
0 голосов
/ 31 августа 2018

build.gradle (лишние части были опущены):

apply plugin: 'java'

repositories {
    mavenCentral()
    maven {
        credentials {
            username "$mavenUser"
            password "$mavenPassword"
        }
        url "http://localhost:8081/nexus/content/groups/public"
    }
}

dependencies {
    compile("com.example:some-lib:1.0.0-RELEASE")
}

Предположим, что в настроенном репозитории Maven отсутствует определенная зависимость. При выполнении ./gradlew clean build задач приложение успешно создается, хотя необходимые зависимости отсутствуют.

Есть ли способ настроить Gradle на сбой при наличии неразрешенных зависимостей?


Относится к:

1 Ответ

0 голосов
/ 01 сентября 2018

Учитывайте это build.gradle ( примечание: намеренно поддельная банка, указанная в dependencies):

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile("junit:junit:4.12")
    compile("junit:junitxyz:51.50")
}

task checkDependencies() {
    doLast {
        configurations.compile.each { file ->
            println "TRACER checking: " + file.name
            assert file.exists() 
        }
    }
}

compileJava.dependsOn checkDependencies

пример вывода:

$ gradle -q clean compileJava

FAILURE: Build failed with an exception.
[snip]

* What went wrong:
Execution failed for task ':checkDependencies'.
> Could not resolve all files for configuration ':compile'.
   > Could not find junit:junitxyz:51.50.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/junit/junitxyz/51.50/junitxyz-51.50.pom
       - https://repo.maven.apache.org/maven2/junit/junitxyz/51.50/junitxyz-51.50.jar
...