gradle - 如何强制 gradle 依赖项工件版本
问题描述
现在我正在使用此代码强制 Gradle 6.0.1 中的版本:
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'redis.clients') {
details.useVersion "3.0.1"
}
if (details.requested.group == 'com.github.jsqlparser') {
details.useVersion "2.1"
}
if (details.requested.group == 'com.squareup.okhttp3') {
details.useVersion "4.0.0"
}
if (details.requested.group == 'com.github.pagehelper') {
details.useVersion("5.1.11")
}
}
}
}
它工作正常,但现在有一个问题,我有很多依赖项开头com.github.pagehelper
,有没有办法使用组名和工件名称来强制版本?我已经尝试过这种方式:
if (details.requested.group == 'com.github.pagehelper' && !details.requested.module == 'pagehelper') {
details.useVersion("5.1.11")
}
似乎它不起作用。
当我编译时,这是输出:
+ ./gradlew :soa-illidan-multipipeline_master:soa-illidan-service:build -x test
> Configure project :soa-robot-multibranch_master
version info:1.0.0-RELEASE
> Task :soa-illidan-multipipeline_master:soa-illidan-service:generateLombokConfig UP-TO-DATE
> Task :soa-illidan-multipipeline_master:soa-illidan-service:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':soa-illidan-multipipeline_master:soa-illidan-service:compileJava'.
> Could not resolve all files for configuration ':soa-illidan-multipipeline_master:soa-illidan-service:compileClasspath'.
> Could not resolve com.github.pagehelper:pagehelper-spring-boot-starter:5.2.0.
Required by:
project :soa-illidan-multipipeline_master:soa-illidan-service > com.sportswin.soa:soa-illidan-api:1.0.33-RELEASE > com.sportswin.misc:soa-misc:1.0.13-RELEASE
> Could not resolve com.github.pagehelper:pagehelper-spring-boot-starter:5.2.0.
> Could not get resource 'https://nexus.example.com/repository/maven-snapshots/com/github/pagehelper/pagehelper-spring-boot-starter/5.2.0/pagehelper-spring-boot-starter-5.2.0.pom'.
> Could not GET 'https://nexus.example.com/repository/maven-snapshots/com/github/pagehelper/pagehelper-spring-boot-starter/5.2.0/pagehelper-spring-boot-starter-5.2.0.pom'. Received status code 400 from server: Repository version policy: SNAPSHOT does not allow version: 5.2.0
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
解决方案
现在我这样做:
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.github.pagehelper' && details.requested.name == 'pagehelper' ) {
details.useVersion("5.2.0")
}
}
}
推荐阅读
- sql-server - AZURE SQL MI 错误:由于数据库关闭,数据库 id '10' 的陈旧/中止版本清理被中止
- c# - 垃圾收集器 - 我声明静态列表时的行为
- drake - Drake URDF:多关节单传动
- flask - 使用不同的数据库进行开发与生产 Flask
- python - 仅将列名和`_`添加到特定列中的每个值
- r - R如果值落在向量中的范围之间,则分配多个类(简单方式)
- c++ - Makefile 中隐式规则中的 -c 标志错误
- c - 什么是在 C 中解析二进制文件的高效且干净的方法?
- jsonschema - "$ref": "#" 是什么意思?
- powershell - 将 power-shell 命令输出到在 if else 语句中不起作用的变量