我想在 Eclipse 的 Gradle java-library 项目中使用 Google 的 Auto-Value。
我的类(class):
@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?
最佳答案
好的,您永远不应该在午夜后编写代码。并且您应该通过丢弃午夜后编写的任何代码来解决问题。
源代码完全是错误的。私有(private)字段而不是抽象方法,autoValue 自动生成类的假名称。
不便之处,敬请谅解。无需进一步答复。使用 google 找到的所有文档均有效。
关于eclipse - 如何使用 Eclipse 和 Gradle 配置 Auto-Value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55787517/