【问题标题】:Maven and Ivy dependency resolution fails with Gradle 6.0Gradle 6.0 的 Maven 和 Ivy 依赖解析失败
【发布时间】:2020-01-25 21:00:51
【问题描述】:

我有一个工作项目,它依赖于这样的对等组件生成的 Maven 工件:

repositories {
   ivy {
       url "../cnf/local"
   }
}

configurations {
  ejbTools
}

dependencies {
  ejbTools 'test:com.ibm.ws.ejbcontainer.fat_tools:1.+'
}

依赖test:com.ibm.ws.ejbcontainer.fat_tools:1.+ 无法使用 Gradle 6.0 解决,并出现以下错误:

> Task :com.ibm.ws.ejbcontainer.async_fat:addEJBTools FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/aguibert/dev/git/open-liberty/dev/com.ibm.ws.ejbcontainer.async_fat/build.gradle' line: 32

* What went wrong:
Execution failed for task ':com.ibm.ws.ejbcontainer.async_fat:addEJBTools'.
> Could not resolve all files for configuration ':com.ibm.ws.ejbcontainer.async_fat:ejbTools'.
   > Could not find any matches for test:com.ibm.ws.ejbcontainer.fat_tools:1.+ as no versions of test:com.ibm.ws.ejbcontainer.fat_tools are available.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/test/com.ibm.ws.ejbcontainer.fat_tools/maven-metadata.xml
       - http://public.dhe.ibm.com/ibmdl/export/pub/software/olrepo/test/com.ibm.ws.ejbcontainer.fat_tools/maven-metadata.xml
       - file:/Users/aguibert/dev/git/open-liberty/dev/cnf/local/test/com.ibm.ws.ejbcontainer.fat_tools/
       - file:/Users/aguibert/dev/git/open-liberty/dev/cnf/local/test/com.ibm.ws.ejbcontainer.fat_tools/1.0.33.201909241016/ivy-1.0.33.201909241016.xml
     Required by:
         project :com.ibm.ws.ejbcontainer.async_fat

上下文

目前我的项目使用的是 Gradle 5.5,可以使用 Java 8、11 或 12 构建。我正在尝试让它与 Java 13 一起使用,因此我正在尝试升级到 Gradle 6.0。

现在,通配符依赖项在 Gradle 中的工作方式似乎发生了普遍的行为变化(例如 com.foo:bar:1.+)。

【问题讨论】:

    标签: maven gradle dependency-management ivy


    【解决方案1】:

    根据this Gradle issue,Gradle 6.0 中的行为发生了重大变化。之前,Gradle 会自动检查工件元数据(例如maven-metadata.xml),但为了提高性能,Gradle 6.0 似乎不再默认这样做。

    这个问题有两种可能的解决方案:

    1. 使用特定的依赖坐标而不是通配符版本,如 1.+(这是 IMO 的最佳实践)

    2. 更新repositories.[maven|ivy].metadataSources 配置。在 Gradle 5.X 中,默认值为:

      repositories {
          maven {
              url "http://repo.mycompany.com/repo"
              metadataSources {
                  mavenPom()
                  artifact()
              }
          }
          ivy {
              url "http://repo.mycompany.com/repo"
              metadataSources {
                  ivyDescriptor()
                  artifact()
              }
          }
      }
      

      但在 Gradle 6.0 中,它们现在是:

      repositories {
          maven {
              url "http://repo.mycompany.com/repo"
              metadataSources {
                  mavenPom()
              }
          }
          ivy {
              url "http://repo.mycompany.com/repo"
              metadataSources {
                  ivyDescriptor()
              }
          }
      }
      

      所以要恢复到以前的行为,请将artifact() 配置添加到repositores.[maven|ivy].metadataSources 配置块。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2013-04-16
      • 2011-05-14
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      相关资源
      最近更新 更多