Gradle 下载旧的编译依赖项

Gradle downloads old compile dependencies

我正在使用 spring-boot 和 gradle。我想使用最新的 selenium 版本,但是一半的编译依赖项(包括驱动程序)不知何故是 3.14 版本。我尝试使缓存失效,./gradlew clean build./gradlew build --refresh-dependencies,但没有用。我的旧项目有相同的依赖项(但没有 spring-boot),我不存在这个问题。

import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
    id 'org.springframework.boot' version '2.6.7'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'xxx.xxxxxx'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
    implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
    // https://mvnrepository.com/artifact/org.testng/testng
    testImplementation 'org.testng:testng:7.5'
    // https://mvnrepository.com/artifact/io.rest-assured/rest-assured
    testImplementation 'io.rest-assured:rest-assured:4.5.1'
    // https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
    implementation 'io.github.bonigarcia:webdrivermanager:5.1.1'
    // https://mvnrepository.com/artifact/com.github.javafaker/javafaker
    implementation 'com.github.javafaker:javafaker:1.0.2'
    // https://mvnrepository.com/artifact/org.assertj/assertj-core
    testImplementation 'org.assertj:assertj-core:3.22.0'

}

test {
    useTestNG()

    testLogging {
        exceptionFormat(TestExceptionFormat.FULL)
    }

    systemProperties(System.getProperties())
}

Spring Boot 管理 Selenium 的版本,因此在您的情况下,您只指定了 selenium-java 的版本,所有其他版本都由 Spring Boot 管理。要正确更新所有 Selenium 依赖项,您必须覆盖 Selenium 版本的 属性:

ext['selenium.version'] = '4.1.4'

并从 selenium-java 条目中删除版本:

implementation 'org.seleniumhq.selenium:selenium-java'

您可以在文档中找到由 Spring Boot 管理的库的所有可用属性:https://docs.spring.io/spring-boot/docs/2.6.7/reference/htmlsingle/#appendix.dependency-versions.properties