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?

nogridbag
  • 3,521
  • 4
  • 38
  • 51

2 Answers2

0

As the Dagger prefixed classes are generated, you should setup eclipse to generate them during the build process by configuring the dagger-compiler's jar into the factory path of your project

For automating this process using maven see this question which uses apt-maven-plugin

Community
  • 1
  • 1
Avinash R
  • 3,101
  • 1
  • 27
  • 47
0

You could try using the maven-processor-plugin to specify a specific target for the annotation processors, probably something like this:

<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>

I haven't tested this yet, but it might work. Sourced the idea from this question: Setting the generated source directory for annotation processors in Maven

Community
  • 1
  • 1
Bart Enkelaar
  • 695
  • 9
  • 21