0

我有两个模块:

  • 基础库
  • 服务

base-lib一些 Spring Boot/Security 依赖项以及一些 Azure 依赖项。Azure 需要特定版本的 nimbusds,因此我将该依赖项设置为特定版本 (5.64.4)。当我自己构建第一个模块时,gradle 只下载 5.64.4。但是当我将它作为另一个模块(没有其他依赖项)的项目依赖项包含在内时,它会下载两个版本:5.64.4 和 6.0。为什么会有所不同?

基础库:build.gradle

buildscript {

    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: "java"
apply plugin: "java-library"
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"

group "${group}"
version "${version}"

sourceCompatibility = 11.0

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {

    api( [ "com.nimbusds:oauth2-oidc-sdk:5.64.4" ] )

    /* These are what pulls in 6.0 */
    api( [ "org.springframework.boot:spring-boot-starter-security:${springBootVersion}" ] )
    api( [ "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springBootVersion}" ] )
    api( [ "org.springframework.security:spring-security-oauth2-client:${springOAuthClientVersion}" ] )

    //Microsoft Azure AD
    api( [ "com.microsoft.azure:adal4j:${adal4jVersion}" ] )

    /* elided, lot's of other dependencies here */
}

服务构建.gradle

dependencies {
    implementation project(":base-lib")
}

如果我删除第二个模块 ( service) 并构建第一个模块,那么它只会下载 5.64.4。但是当我同时拥有它们并构建它们时,它也会降低 6.0。

这可以解决它,但是为什么在作为项目依赖项而不是正常情况下需要这样做?为什么依赖规则不同?

api( [ "com.nimbusds:oauth2-oidc-sdk:5.64.4" ] ) {
    force = true
}
4

1 回答 1

1

解决此类问题的最佳方法是dependencyInsight有问题的依赖项上使用任务。

在您的情况下,最可能的解释是您的项目base-lib使用了 Spring boot 和 Spring 依赖项管理插件。这些插件将根据 Spring Boot BOM 强制执行多个版本,但也有一个功能,即使用版本声明的任何依赖项都会覆盖来自 BOM 的内容。并且由于您指定了它的版本,oauth2-oidc-sdk因此确实获得了该版本。

现在,当您将所有这些依赖项传递到 中时service,不会应用依赖项管理插件。因此默认 Gradle 解析规则适用,这意味着在5.64.46.0版本之间,Gradle 将选择最高的。

可以通过在您试验时强制版本或通过应用相同的插件并再次声明来完成修复。

于 2018-12-20T18:46:26.320 回答