Gradle 8中Jar任务出现getConvention()弃用警告,不知如何适配
Gradle 8 Jar任务触发
getConvention()废弃警告的解决办法 问题描述
我有一个配置了如下Jar任务的Gradle脚本:
jar { manifest { attributes('Specification-Title': 'RSyntaxTextArea', 'Automatic-Module-Name': 'org.fife.RSyntaxTextArea', // jdk 9+ module name 'Specification-Version': version, 'Implementation-Title': 'org.fife.ui', 'Implementation-Version': version, 'Bundle-License': 'BSD-3-Clause', // Not sure why Require-Capability is not being added by the osgi plugin... 'Require-Capability': 'osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=' + javaVersion + '))"') } }
使用Gradle 8并加上--warning-mode all参数构建时,收到了如下警告:
The AbstractTask.getConvention() method has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information.
官方升级文档只给出了War和Ear任务的配置示例(通过闭包属性而非约定属性配置),但我的Jar任务写法已经遵循该模式,网上的Jar Manifest配置示例也和我的一致,完全搞不懂需要修改什么。
解决方案
这个警告不是来自你写的manifest闭包配置,而是OSGi插件内部调用了已废弃的getConvention()方法导致的。你当前的Jar任务写法本身完全符合Gradle 8+的规范,不需要修改自己的代码。
想要消除这个警告,可以试试这两种方法:
- 升级OSGi插件到最新版本:新版本的插件大概率已经修复了这个废弃API的使用问题。
- 临时抑制该警告:在项目的
gradle.properties文件中添加以下配置,针对该特定废弃API关闭警告:
不过这种方法只是临时规避,长远来看还是优先升级插件版本更稳妥。org.gradle.warning.mode=all org.gradle.deprecations.mute=AbstractTask.getConvention()
内容的提问来源于stack exchange,提问作者bobby_light
相关产品推荐
相关产品推荐

