gradle - 如何根据坐标字符串解决gradle依赖
问题描述
对于我的构建,我需要根据一些条件逻辑有条件地解析一个 jar。我需要 jar 文件的位置,而不是将其放入特定构建或运行时配置的类路径中。
if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
def alpnBootVersion = alpnBootVersion()
if (alpnBootVersion != null) {
dependencies {
testCompile "org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion"
}
def alpnBootJar = configurations.testCompile.find { it.name.startsWith("alpn-boot-") } <-- fails here
test {
jvmArgs += "-Xbootclasspath/p:${alpnBootJar}"
}
}
}
这现在失败了
如何将 jar 解析为本地路径?
解决方案
仅为该工件创建配置
def jarPath = configurations.detachedConfiguration(
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
).singleFile
推荐阅读
- dapper - 使用多个数据库时的内存使用量更小
- r - 使用 rvest 抓取推文计数
- python - 如何从Python3中的给定值列表中获取字符串中每个字符的值?
- python - 尝试将 git HEAD 重置为上次提交时无法解析对象
- user-interface - 在 GUI scilab 中显示文件地址,为什么 uicontrol 返回 undefined
- swift - 使用蒸汽时 Timer.scheduledTimer 不可用?
- security - 使用 AES128 和 ECB 操作模式的漏洞
- html - 必需的标记在 HTML 表单中不起作用
- docker - 是否可以将 docker 容器的重启策略的默认时间更改为 10 秒?
- sql - 使用 SSIS 或 SQL 将多个 XML 整理成单个 XML