首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gradle是否支持版本中的逗号来指定几个范围?

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

Stack Overflow用户
提问于 2017-12-21 12:58:21
回答 2查看 445关注 0票数 0

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

比如:

代码语言:javascript
复制
dependencies {
  compile 'org.webjars.npm:minimatch:2.+,3.+'
}

或者:

代码语言:javascript
复制
  compile 'org.webjars.npm:minimatch:[2,3),[3,4)'

在Maven是允许的

(,1.0 ),[ 1.2,]x <= 1.0或x >= 1.2。多个集合以逗号分隔。 (, 1.1 ),(1.1,)如果已知不与本库一起工作,则不包括1.1

适用于:

代码语言:javascript
复制
dependencies {
    compile(group: 'org.webjars.npm', name: 'glob', version: '5.0.15') {
}

它失败的原因是:

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-12-21 14:49:29

我不认为Gradle支持这样的多版本范围,而是支持单个范围。您应该搜索问题跟踪器,这是否已经报告,并打开一个新的问题,如果不是,这样它可以得到最终的解决。

为了解决这个问题,您可以使用该库的更新版本,在最新版本中,它不使用多个范围,而是只使用单个范围。

或者,您可以排除传递依赖并自己包含一个版本,或者编写一个针对该范围选择特定版本的依赖关系解决规则。

如果您还想使用老版本的,那么其中的一个应该会有所帮助。

代码语言:javascript
复制
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.+'
}
代码语言:javascript
复制
configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module("org.webjars.npm:minimatch") with module("org.webjars.npm:minimatch:3.0.4") 
    }
}
代码语言:javascript
复制
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'
        }
    }
}
票数 1
EN

Stack Overflow用户

发布于 2017-12-21 13:52:31

Gradle使用Ivy来解决依赖关系:

代码语言:javascript
复制
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver.resolveModule(RepositoryChainComponentMetaDataResolver.java:105)

Ivy不支持版本列表,至少我在docs中找不到示例:

  • http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html
  • http://ant.apache.org/ivy/history/latest-milestone/settings/version-matchers.html

我像往常一样解决了问题:

代码语言:javascript
复制
dependencies {
    compile(group: 'org.webjars.npm', name: 'glob', version: '5.0.15') {
        exclude module: 'minimatch'
    }
    compile 'org.webjars.npm:minimatch:3.0.4'
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47925540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档