3

我想在 Eclipse 的 Gradle java-library 项目中使用 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 中使用 Auto-Value,只需使用:

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,没有那个插件我应该没问题。

如何整合 i Auto-Value?

4

1 回答 1

0

好的,你不应该在午夜之后编码。您应该通过丢弃午夜之后编写的任何代码来解决问题。

源代码就是错误的。私有字段而不是抽象方法,autoValue 自动生成类的错误名称。

对造成的不便表示歉意。无需进一步回复。用谷歌找到的所有文档都是有效的。

于 2019-04-22T14:00:57.777 回答