【问题标题】:Does gradle support comma in version to specify several ranges?gradle 是否支持版本中的逗号来指定多个范围?
【发布时间】:2017-12-21 12:58:21
【问题描述】:

Gradle 是否支持版本中的逗号来指定多个范围?

喜欢:

dependencies {
  compile 'org.webjars.npm:minimatch:2.+,3.+'
}

或:

  compile 'org.webjars.npm:minimatch:[2,3),[3,4)'

It is allowed in Maven:

(,1.0],[1.2,) x = 1.2。多个集合以逗号分隔

(,1.1),(1.1,) 如果已知不能与此库结合使用,则不包括 1.1

为:

dependencies {
    compile(group: 'org.webjars.npm', name: 'glob', version: '5.0.15') {
}

它失败了:

Execution failed for task ':dump'.
> Could not resolve all files for configuration ':runtime'.
  > Could not find org.webjars.npm:minimatch:[2,3),[3,4).
  Searched in the following locations:
     https://repo1.maven.org/maven2/org/webjars/npm/minimatch/[2,3),[3,4)/minimatch-[2,3),[3,4).pom
     https://repo1.maven.org/maven2/org/webjars/npm/minimatch/[2,3),[3,4)/minimatch-[2,3),[3,4).jar
     https://jcenter.bintray.com/org/webjars/npm/minimatch/[2,3),[3,4)/minimatch-[2,3),[3,4).pom
     https://jcenter.bintray.com/org/webjars/npm/minimatch/[2,3),[3,4)/minimatch-[2,3),[3,4).jar
 Required by:
     project : > org.webjars.npm:glob:5.0.15

【问题讨论】:

    标签: gradle versioning


    【解决方案1】:

    我认为 Gradle 还不支持这样的多个版本范围,但支持单个范围。您应该在问题跟踪器中搜索是否已报告此问题,如果没有则打开一个新问题,以便最终修复。

    要解决此问题,您可以使用该库的较新版本,在最新版本中,它不使用多个范围,而只使用单个范围。
    或者,您可以排除传递依赖并自己包含一个版本,或者编写一个依赖解析规则,为该范围选择特定版本。

    其中一个应该会有所帮助,如果您仍想使用旧版本的 glob,我会说。

    dependencies {
        compile(group: 'org.webjars.npm', name: 'glob', version: '5.0.15') {
            exclude group: 'org.webjars.npm', module: 'minimatch'
        }
        runtime 'org.webjars.npm:minimatch:3.+'
    }
    

    configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute module("org.webjars.npm:minimatch") with module("org.webjars.npm:minimatch:3.0.4") 
        }
    }
    

    configurations.all {
        resolutionStrategy.eachDependency {
            if ((it.requested.group == 'org.webjars.npm') && (it.requested.name == 'minimatch')) {
                it.useTarget group: it.requested.group, name: it.requested.name, version: '3.0.4'
            }
        }
    }
    

    【讨论】:

    【解决方案2】:

    Gradle 使用 Ivy 解决依赖关系:

    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver.resolveModule(RepositoryChainComponentMetaDataResolver.java:105)
    

    而且 Ivy 不支持版本列表,至少我在文档中找不到示例:

    我照常解决问题:

    dependencies {
        compile(group: 'org.webjars.npm', name: 'glob', version: '5.0.15') {
            exclude module: 'minimatch'
        }
        compile 'org.webjars.npm:minimatch:3.0.4'
    }
    

    【讨论】:

    • Gradle 使用 Ivy 进行依赖解析。它支持一些 Ivy 语法并支持 Ivy 存储库,但它具有完整的自己的依赖关系解析机制。我认为 Gradle 目前不支持多个范围是正确的,建议的解决方案是解决它的一种方法,但是 Ivy 文档在这里不合适,并且 Ivy 用于依赖解决方案的声明显然是错误的。 :-)
    猜你喜欢
    • 2011-03-05
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2015-05-15
    • 1970-01-01
    相关资源
    最近更新 更多