是否可以使用Spring的Gradle依赖性管理插件来设置dependencySet条目的分类器 [英] Is it possible to set a dependencySet entry's classifier using Spring's Gradle dependency management plugin

查看:84
本文介绍了是否可以使用Spring的Gradle依赖性管理插件来设置dependencySet条目的分类器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring的项目多项目Gradle构建中的依赖管理插件,用于为项目指定一致的依赖版本.

I have a project that uses the Spring Dependency Management Plugin in a multi-project Gradle build to specify consistent dependency versions for the projects.

每个

Per the documentation, when multiple dependencies share the same group & version, a dependency set should be used:

当您要为具有相同组和版本的多个模块提供依赖项管理时,应使用依赖项集.使用依赖集可以避免多次指定相同的组和版本,如下面的示例所示:

When you want to provide dependency management for multiple modules with the same group and version you should use a dependency set. Using a dependency set removes the need to specify the same group and version multiple times, as shown in the following example:

dependencyManagement {
     dependencies {
          dependencySet(group:'org.slf4j', version: '1.7.7') {
               entry 'slf4j-api'
               entry 'slf4j-simple'
          }
     }
}

项目使用共享一个组和版本的两个依赖项,但是其中一项还指定了一个分类器:

The project uses two dependencies that share a group and version, but one of the items also specifies a classifier:

dependencies {
  annotationProcessor 'com.querydsl:querydsl-apt:4.2.2:general'
  implementation 'com.querydsl:querydsl-mongodb:4.2.2'
}

如果在这种情况下可以使用 dependencySet ,我在文档或在线搜索中都找不到它:

If there's a way to use a dependencySet in this case, I haven't found it in the documentation or an online search:

dependencyManagement {
    dependencies {
        dependencySet(group:'com.querydsl', version: '4.2.2') {
            entry 'querydsl-apt' // Can I specify that this uses the "general" classifier?
            entry 'querydsl-mongodb'
        }
    }
}

简而言之,当其中一个依赖项需要分类器时,有没有一种使用 dependencySet 的方法,这样做的语法是什么?

So in short, is there a way to use a dependencySet when one of the dependencies requires a classifier, and what is the syntax for doing so?

推荐答案

已关闭处于拒绝"状态的维护者由插件维护者负责:

Issue #67 for the Dependency Management Plugin requests this feature. The issue was closed by the maintainers with a status of "declined" by the plugin maintainers:

当分类器仍然是Gradle中的二等公民时,实现这一点是不可能的.我不希望这种情况很快就会改变(Gradle 3.0中的情况没有改善),因此,遗憾的是,我将结束本次讨论.

It's impossible to implement this while classifiers remain a second class citizen in Gradle. I don't expect that will change any time soon (things haven't improved in Gradle 3.0) so, with some regret, I'm going to close this.

该问题的后续讨论表明,Gradle 6仍未解决潜在的Gradle问题.

Follow-up conversation in that issue suggest that the underlying Gradle issue is still not resolved in Gradle 6.

这意味着不仅不能使用 dependencySet 指定分类器,而且不能使用 dependencyManagement 部分中的 dependency 条目指定分类器:

This means that not only can classifiers not be specified using dependencySet, they cannot be specified using dependency entries within the dependencyManagement section either:

dependencyManagement {
    dependencies {
        dependency 'com.querydsl:querydsl-apt:4.2.2:general' // INVALID
        dependency 'com.querydsl:querydsl-mongodb:4.2.2'
    }
}

更糟糕的是,没有警告或失败发出,因此用户不明白它没有使用带有分类器的指定版本.

What's worse, there is no warning or failure emitted, so the fact that it's not using the specified version with a classifier is not made clear to the user.

所以要回答这个问题,由于Gradle没有为插件提供访问分类器的API,因此不支持在dependencyManagement插件中使用分类器.因此,不能在 dependencyManagement 部分中直接使用 dependency 或使用 dependencySet 作为组来指定带有分类器的依赖版本.

So to answer the question, the usage of classifiers in the dependencyManagement plugin is not supported since Gradle does not provide an API for the plugin to access the classifier. Therefore, dependency versions with classifiers cannot be specified in the dependencyManagement section either directly using dependency or as a group using dependencySet.

这篇关于是否可以使用Spring的Gradle依赖性管理插件来设置dependencySet条目的分类器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆