1

This might simply be a maven question. I'm just getting started with Dagger 2 which uses javax.annotation.processing to generate sources based on annotations.

When I use my IDE, IntelliJ, and build the project (Build - Rebuild Project) it places the generated sources files (i.e. $$Factory and Dagger_) in:

target/generated-sources/annotations

IntelliJ automatically declares this as a source root so using the generated classes doesn't get marked as an error:

// Dagger_CoffeeApp$$Coffee is a generated class
Coffee coffee = Dagger_CoffeeApp$Coffee.builder().build();

The problem is that if I build from the command line via maven:

mvn clean compile

The generated sources are located in:

target/classes

And thus the files are marked with an error in my IDE. I could probably simply add target/classes as a source root, but ideally I would like compiling from the command line to be consistent with my IDE. Is there some argument to maven to specify which directory the generated sources files are generated in?

4

2 回答 2

0

随着前缀类的生成,您应该通过将dagger-compiler的 jar配置Dagger到项目的工厂路径中来设置 eclipse 以在构建过程中生成它们

要使用 maven 自动化此过程,请参阅使用apt-maven-plugin 的这个问题

于 2015-04-16T16:42:58.133 回答
0

您可以尝试使用 maven-processor-plugin 为注释处理器指定特定目标,可能是这样的:

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>1.0-SNAPSHOT</version>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <outputDirectory>target/generated-sources/annotations</outputDirectory>
      </configuration> 
    </execution>
  </executions>
</plugin>

我还没有对此进行测试,但它可能会起作用。从这个问题中获取想法:在 Maven 中为注释处理器设置生成的源目录

于 2015-04-22T21:58:14.447 回答