Search code examples
javamavenmaven-2

How to add an extra source directory for maven to compile and include in the build jar?


In addition to the src/main/java, I am adding a src/bootstrap directory that I want to include in my build process, in other words, I want maven to compile and include the sources there in my build. How!?


Solution

  • You can use the Build Helper Plugin, e.g:

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