【发布时间】:2021-08-11 17:07:49
【问题描述】:
我正在开发一个自定义二进制 Gradle 插件,遵循here 显示的模式。
我的扩展,VersionInfoExtension 是带有抽象方法的抽象,就像文档中的 BinaryRepositoryExtension 一样。我的任务也是抽象的,带有参数的抽象方法,例如文档中的 LatestArtifactVersion。当我测试时,我收到以下错误:
An exception occurred applying plugin request [id: 'com.example.version-info']
> Failed to apply plugin 'com.example.version-info'.
> Could not create an instance of type com.example.gradle.version.VersionInfoExtension.
> Could not generate a decorated class for type VersionInfoExtension.
> Cannot have abstract method VersionInfoExtension.jars().
我错过了什么?有没有很好的例子来实现这项工作?
【问题讨论】:
-
您的扩展程序在使用时可能尚未配置,这可能意味着它正在应用方法中使用。您需要确保在任务中使用任何扩展值,而不是作为应用的结果。文档对此并不十分清楚。您可以在类中使用 init 块来帮助使用默认值
-
@BenjaminCharais,您能详细说明您的上述观点吗?我开发的插件和扩展也遇到了同样的问题!
标签: java gradle gradle-plugin