现在我正在使用此代码强制 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.
答案 0 :(得分:0)
现在我是这样做的:
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.github.pagehelper' && details.requested.name == 'pagehelper' ) {
details.useVersion("5.2.0")
}
}
}