Archive

Posts Tagged ‘generated sources’

Maven snippet – add generated sources to the build

July 21, 2014 Leave a comment

Here’s a maven snippet I found myself looking for many times – adding generated sources to the build.
This tells Maven to include the generated classes as part of the compilation, which ensures any non generated code that depends on them compiles fine, and their corresponding .class files be included in the .jar/.war file.

  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    ...
    </plugins>
  </build>
  ...

In this case (line #153) – we assume that the sources are generated to target/generated.

Some useful reading material regarding this subject:

%d bloggers like this: