Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven: how to include annotation-generated .java files in the .jar

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?

like image 455
TmTron Avatar asked Oct 19 '25 04:10

TmTron


1 Answers

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,

like image 167
Anders R. Bystrup Avatar answered Oct 21 '25 18:10

Anders R. Bystrup



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!