Eclipse AutoValue类无法构建 [英] Eclipse AutoValue class fails to build

查看:210
本文介绍了Eclipse AutoValue类无法构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Eclipse Kepler SR2,Maven 3.1.1附带m2e和m2e-apt插件,我收到错误,我不知道如何解决。



我设法找到了获得 in AutoValue的版本 1.0-rc1 ,在jsr305依赖项上有一条注释必须有处理器运行的地方。在 1.0-rc1 <发布后,已被删除 / code>,因此在版本 1.0 时可能不需要将它添加到注释处理器工厂路径。



另见此博客发布,了解如何在Eclipse中使用AutoValue。


I'm running Eclipse Kepler SR2, with Maven 3.1.1 attached with the m2e and m2e-apt plugins, and I'm getting an error I don't know how to resolve.

I managed to find all the dependencies needed to get @AutoValue working into my pom.xml, but now I'm in a state where it only works if the methods which need to be defined all have primitive return types. If I provide an abstract getter which returns an Object or more specific, I get this error:

@AutoValue processor threw an exception:
  java.lang.IllegalArgumentException:
    Failed to invoke com.google.auto.value.processor.AutoValueProcessor$Property.nullable() on getObject...

I've tried the basics - cleared the maven cache, restarted Eclipse, rebuilt the project... no dice. So I dug down into the source code and I found a discrepancy which I'm not sure how it's intended to be resolved.

In the Velocity template for the generated AutoValue class, there is some basic logic for rendering primitives differently than objects, for instance on line 37, p.nullable is checked. The p variable is an instance of AutoValueProcessor$Property class, which, as can be seen on line 205 of the preceeding link, has an isNullable() method, but no nullable method or property.

How is the Velocity rendering phase intended to work then? Does Velocity auto-expand p.nullable to p.isNullable some how, but not for me because reasons? Is this a bug? I'm not sure what to do from here.


Example class that doesn't compile:

@AutoValue
public abstract class Point {

  public static Point of(double x, double y) {
    return new AutoValue_Point(x, y);
  }

  public abstract Double x();

  public abstract Double y();

}

Eclipse highlights the described error under Point at the head of the class declaration.

解决方案

It appears that the dependency com.google.code.findbugs:jsr305 is missing when Eclipse runs the annotation processor. Try adding it by opening the project properties, browsing to Java Compiler -> Annotation Processing -> Factory Path, clicking on "Add External JARs" and then selecting the jsr305 JAR. If you have built the project with maven from the command line, you should be able to select the JAR from your .m2 directory.

Here's what the proprties look like in my project (the first entry is automatically added by Eclipse and doesn't seem to be relevant):

In the pom.xml in version 1.0-rc1 of AutoValue, there is a comment "Must have this where procesor runs" at the jsr305 dependency. The dependency was removed after the release of 1.0-rc1, so adding it to the annotation processor factory path will probably not be necessary with version 1.0.

See also this blog post for an introduction to using AutoValue with Eclipse.

这篇关于Eclipse AutoValue类无法构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆