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

Does gradle support comma in version to specify several ranges?

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.0 or x >= 1.2. Multiple sets are comma-separated

(,1.1),(1.1,) This excludes 1.1 if it is known not to work in combination with this library

对于:

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 使用 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 还不支持这样的多个版本范围,但支持单个范围。您应该在问题跟踪器中搜索是否已报告此问题,如果没有,请打开一个新问题,以便最终得到修复。

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

其中一个应该有帮助我想说如果你还想使用旧版本的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'
        }
    }
}