我有一个自定义编译任务.
task compileSpeedTest(type: JavaCompile) {
classpath = files('build')
source = fileTree('src/test/java/speed')
destinationDir = file('bin')
}
Run Code Online (Sandbox Code Playgroud)
Gradle在执行之前不会尝试下载依赖项.我找不到一个任务名称,它将它添加到列表dependsOn上.
Evg*_*eny 44
如果您确实需要将它们下载到文件夹中,则可以下载Java依赖项.
例:
apply plugin: 'java'
dependencies {
runtime group: 'com.netflix.exhibitor', name: 'exhibitor-standalone', version: '1.5.2'
runtime group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.4.6'
}
repositories { mavenCentral() }
task getDeps(type: Copy) {
from sourceSets.main.runtimeClasspath
into 'runtime/'
}
Run Code Online (Sandbox Code Playgroud)
下载依赖(和它们的依赖)进入该文件夹runtime,当你执行gradle getDeps.
Har*_*own 16
我发现这个答案/sf/answers/3297499481/也很有帮助:
gradle dependencies将列出依赖项并将它们作为副作用下载。
Rob*_*iot 12
稍微轻松的任务,不会不必要地将文件复制到目录:
task downloadDependencies(type: Exec) {
configurations.testRuntime.files
commandLine 'echo', 'Downloaded all dependencies'
}
Run Code Online (Sandbox Code Playgroud)
小智 6
你应该尝试这个:
task getDeps(type: Copy) {
from configurations.runtime
into 'runtime/'
}
Run Code Online (Sandbox Code Playgroud)
前一段时间我正在寻找它,当时我们必须在我们的配置脚本中的某个时刻将所有依赖项下载到当前工作目录中.我想你正在努力实现类似的东西.
这个版本建立在罗伯特·艾略特(Robert Elliot)的基础上,但我不确定它的功效。
// There are a few dependencies added by one of the Scala plugins that this cannot reach.
task downloadDependencies {
description "Pre-downloads *most* dependencies"
doLast {
configurations.getAsMap().each { name, config ->
println "Retrieving dependencies for $name"
try {
config.files
} catch (e) {
project.logger.info e.message // some cannot be resolved, silentlyish skip them
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试将其设置为配置而不是操作(通过删除doLast),它破坏了锌。我解决了这个问题,但是无论有没有最终结果都是一样的。因此,我将其保留为明确状态。它似乎足以减少以后必须下载的依赖项,但就我而言,并不能消除它们。我认为Scala插件之一会在以后添加依赖项。
Pet*_*ser -9
没有下载依赖的任务;它们是按需下载的。要了解如何使用 Gradle 管理依赖项,请参阅Gradle 用户指南中的“第 8 章依赖项管理基础知识” 。
| 归档时间: |
|
| 查看次数: |
90576 次 |
| 最近记录: |