首页 > 解决方案 > 如何根据坐标字符串解决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 解析为本地路径?

标签: gradle

解决方案


仅为该工件创建配置

def jarPath = configurations.detachedConfiguration(
  dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
).singleFile

推荐阅读