Question

I have some java 7 annotation processors (for xtend) on my class-path. Via some annotations they create java files.
This works great, in Elipse and in the Maven build.

The generated files end up in target/generated-sources/annotations as expected.
The corresponding generated .class files also end up where expected and are thus part of the final jar file.

Since I need to also include all java source files in my .jar file (there should be only one .jar file with the sources and classes) for GWT, I have specified src/main/java as a resources dir (so that Maven copies the files to the classes dir and they end up in the jar file).

the trick with the resources directory does not really work for my generated files, because Maven will first copy all resources and then start the compilation (which in turn will generate the .java files via the annotation processors).

How can I tell Maven to copy also include the generated .java files in the .jar?

Was it helpful?

Solution

You can bind the maven-resources-plugin to the prepare-package phase to achieve copying annotation sources before packaging proper:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-annotations</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>copy-resources</goal>
          </goals>
          <configuration>
            <resources>
              <resource>
                <directory>target/generated-sources/annotations</directory>
              </resource>
            </resources>
          </configuration>
        </execution>
      </executions>
    </plugin>
   </plugins>
</build>
    ...

I hope that helps.

Cheers,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top