groovy 如何抑制有关已弃用Gradle功能的Gradle警告?

neekobn8  于 2023-02-03  发布在  其他
关注(0)|答案(3)|浏览(251)

我正在使用最新的Gradle v7.2
当我编译时它给了我警告

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings

我检查了--warning-mode all,它只有大约jcenter deprecation

> Configure project :
The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 8.0. JFrog announced JCenter's sunset in February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/7.2/userguide/upgrading_version_6.html#jcenter_deprecation
        at build_akew6bhcr0m9glzogac5s3m6w$_run_closure1.doCall(/Users/paul.verest/Workspaces/Polkadot/bcd-java/build.gradle:10)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)

现在,**如何让gradle忽略build.gradle**中的一行(在本例中为jcenter用法,但也可以是任何用法),以便“Deprecated Gradle features were used”(已使用过时的Gradle功能)消失,
直到新特性被弃用或我的构建脚本得到更改?
是的,这个问题不是关于抑制代码的编译器输出,
但适用于Gradle生成的.gradle文件。
不使用--warning-mode,因为它可以隐藏和显示所有警告。
正是这样,我有依赖性,这只在jcenter上。

cbjzeqam

cbjzeqam1#

抱歉,你可能不喜欢这个答案。
Gradle(7.2)中没有选项来抑制特定的弃用。修复构建文件将更便宜,也更正确。

jhdbpxl9

jhdbpxl92#

替换Gradle文件中的以下存储库

jcenter()

其中:

mavenCentral()

或者:

gradlePluginPortal()

这将假设所需的依赖项存在于maven repo中,您必须通过进行新的构建来进行检查。
当前,jcentral()存储库已关闭。

rqmkfv5c

rqmkfv5c3#

您可以自己配置jcenter资源库,而无需使用过时的helper:

repositories {
    maven {
        name = "jcenter"
        url = uri("https://jcenter.bintray.com/")
    }
}

但是考虑到jcenter目前的状态(逐步淘汰,定期停机),您将处于一个更好的情况下摆脱它。
在公共中央存储库中,Maven Central是目前唯一明智的选择。
请注意,gradlePluginPortal()目前代理jcenter,这会使您的构建对jcenter中断也很敏感。
如果你想限制这些对你的构建的影响,你应该利用存储库内容过滤。

repositories {
    maven {
        name = "jcenter"
        url = uri("https://jcenter.bintray.com/")
        content {
            includeGroup("my.only.dependency.from.jcenter")
        }
    }
    mavenCentral()
}

请参见https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:repository-content-filtering

相关问题