我想在Eclipse的Gradle java库项目中使用Google的Auto-Value。
我的班级:
@AutoValue
public abstract class Pairing implements Comparable<Pairing> {
static Pairing create(final Participant white, final Participant black) {
return new AutoValue_Participant(white, black);
}
private final transient Participant white;
private final transient Participant black;
}https://github.com/google/auto/blob/master/value/userguide/index.md说:要在Gradle中使用自动赋值,只需使用:
dependencies {
// Use 'api' rather than 'compile' for Android or java-library projects.
compile "com.google.auto.value:auto-value-annotations:1.6.2"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
}我这么做了,但它不起作用:
> Task :compileJava FAILED
D:\QNo_Dokumente\Java\workspace\SwissCoffee\src\main\java\de\qno\swisscoffee\Pairing.java:20: error: cannot find symbol
return new AutoValue_Participant(white, black);
^
symbol: class AutoValue_Participant
location: class Pairing
D:\QNo_Dokumente\Java\workspace\SwissCoffee\build\classes\java\main\de\qno\swisscoffee\AutoValue_Pairing.java:11: error: constructor Pairing in class Pairing cannot be applied to given types;然后我谷歌了一下,发现了一个Gradle APT插件,它应该可以解决所有问题。但是这个插件的文档说: Gradle >= 4.6不需要这个插件,而且因为我使用的是gradle 5.4,所以没有这个插件应该没问题。
如何集成Auto-Value?
发布于 2019-04-22 22:00:58
好吧,你永远不应该在午夜之后编写代码。并且您应该通过丢弃午夜后编写的任何代码来解决问题。
源代码根本就是错的。私有字段而不是抽象方法,自动生成的autoValue类的假名称。
很抱歉给您带来不便。不需要进一步的回复。在google上找到的所有文档都是有效的。
https://stackoverflow.com/questions/55787517
复制相似问题