【发布时间】:2015-10-22 07:56:58
【问题描述】:
如何让 Gradle @Input 为 List<CustomClass> 工作?我试过添加toString() 方法,这有帮助,但它仍然以奇怪的方式失败。使其可序列化的正确方法是什么?这是 Gradle 的 2.4 版。
失败:List<CustomClass>
@Input
List<CustomClass> getMyInput() {
List<CustomClass> simpleList = new ArrayList<>()
simpleList.add(new CustomClass())
return simpleList
}
static class CustomClass {
String str
}
失败并显示以下消息:
"Unable to store task input properties. Property 'myInput' with value '[null]' cannot be serialized."
成功:List<String>
@Input
List<String> getMyInput() {
List<String> simpleList = new ArrayList<>()
simpleList.add(new String('ignore'))
return simpleList
}
异常创建位置的 Gradle 源代码参考: https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/internal/changedetection/state/InputPropertiesSerializer.java#L42
【问题讨论】:
-
添加了关于 Gradle 2.4 的注释。我基本上错过了 Serializable 的正确实现。请参阅下面的答案。
标签: gradle gradle-plugin