【问题标题】:Gradle Cannot have abstract methodGradle 不能有抽象方法
【发布时间】: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


【解决方案1】:

我正在使用 gradle 7.X 和 Kotlin。

方法名前缀"is"时报“Cannot have abstract method myPropertyName”错误:

abstract val isRegistered: Property<Boolean>

追踪起来很烦人。类型似乎无关紧要。

解决方案是从名称中删除 "is"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 2016-02-13
    • 2013-11-23
    • 2014-02-17
    • 1970-01-01
    相关资源
    最近更新 更多