build.gradle从8迁移到9

wfveoks0  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(190)

请考虑:

buildscript {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2"
    }
}


apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

// gradle 5.0+ compatibility
configurations.implementation.setCanBeResolved(true)
// gradle 9.0+ compatibility
// change 

// tag::repositories[]
repositories { 
    mavenCentral() 
}


application {
    // Define the main class for the application.
    mainClass = 'd20.App'
}

// end::repositories[]

// tag::dependencies[]
sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    implementation "joda-time:joda-time:2.2"
    testImplementation "junit:junit:4.12"
    implementation 'com.google.code.gson:gson:2.9.0'

}

字符串
以下是警告:
构建文件'/home/bussiere/Workspace/CustomSystem/oldschooljava/build. gradle':第19行配置':implementation'的允许用法正在更改,resolvable为false,现在为true。理想情况下,用法应该在创建时就固定下来。此行为已被弃用。计划在Gradle 9.0中删除此行为。创建时应固定使用。有关详细信息,请参阅升级指南:https://docs.gradle.org/8.1.1/userguide/upgrading_version_8.html#configurations_allowed_usage
我试着抑制这句台词:
configurations.implementation.setCanBeResolved(true)
然后用

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        details.useVersion "latest.release"
    }
}


但不管用

zfciruhq

zfciruhq1#

要使您的脚本与Gradle 9.0兼容,您可以按以下方式修改配置块:

configurations {
    implementation {
        // Set the `canBeResolved` attribute to true upon creation
        canBeResolved = true
    }
}

字符串
在Gradle 9.0中,请确保将configurations.implementation.setCanBeResolved(true)行替换为脚本中的modified configurations块。

相关问题