如何在不运行gradle构建的情况下使用gradle解决所有依赖项



我使用的是6.4.1级。

在我的build.gradle文件中,我应用了许多插件,如mkdocs、sonar等。

此外,我有以下部分:


allprojects {
group = 'blah'
version = '1.0'
apply plugin: 'checkstyle'
repositories {
jcenter()
maven {
url = "${artifactory_url}libs-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_key}"
}
}
}

ext {
springCloudVersion = "Hoxton.SR10"
}
apply plugin: "blah.java"
task allDeps(type: DependencyReportTask) {}
task getRunTimeDeps(type: Copy) {
from sourceSets.main.runtimeClasspath
into 'runtime/'
doFirst {
ant.delete(dir: 'runtime')
ant.mkdir(dir: 'runtime')
}
doLast {
ant.delete(dir: 'runtime')
}
} 
}

这意味着我试图在构建之前创建一些任务来解决依赖关系。

然后,我运行以下命令,试图下载所有项目依赖项:

gradle dependencies
gradle --info allDeps
gradle --info getRunTimeDeps

我可以看到很多依赖项都被下载了。稍后,我运行:

gradle --info build

我可以看到gradle下载了一堆额外的依赖项。例如:

> Task :sub_project:compileJava 
Downloading https://jcenter.bintray.com/org/hibernate/common/hibernate-commons-annotations/5.1.2.Final/hibernate-commons-annotations-5.1.2.Final.jar to /tmp/gradle_download9086773233498314888bin
Downloading https://jcenter.bintray.com/org/hibernate/hibernate-core/5.4.30.Final/hibernate-core-5.4.30.Final.jar to /tmp/gradle_download7503997830142702838bin
Downloading https://jcenter.bintray.com/org/jboss/jandex/2.2.3.Final/jandex-2.2.3.Final.jar to /tmp/gradle_download7604295797727562679bin
Downloading https://jcenter.bintray.com/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.11.0/jackson-module-jaxb-annotations-2.11.0.jar to /tmp/gradle_download16534853131601223061bin
Downloading https://jcenter.bintray.com/org/javassist/javassist/3.27.0-GA/javassist-3.27.0-GA.jar to /tmp/gradle_download3958588894727834776bin

我不明白为什么以前的任务中没有下载依赖项,但有时我会看到插件中的依赖项,它们也没有下载。

我如何执行任务并获得构建任务所需的一切,例如build任务不必下载任何东西?

我认为您所做的allDeps任务应该在可能的情况下解析(从而下载(所有配置。所以我真的不明白,如果你在编译时看到其他文件被下载。也许您使用的插件在配置阶段没有正确地声明配置或依赖关系?

但是您所做的另一个任务getRunTimeDeps只下载了其中的一些,因为它没有考虑到除runtimeClasspath之外的配置。compileOnlyannotationProcessortestImplementation等配置将不包括在内。所以也许可以试试这样的东西:

// Groovy DSL, root project
allprojects {
task cacheDeps {
doLast {
configurations.each { conf ->
if (conf.isCanBeResolved()) {
conf.resolve()
}
}
}
}
}

您尝试过以下操作吗?

./gradlew build --refresh-dependencies

最新更新