Using MOJO build-helper-maven-plugin to add more source folders to MAVEN
The problem is your includes
configuration of the maven-compiler-plugin. The maven-compiler-plugin will automatically pick up all source folders configured in your project - you don't need to define them via the includes
tag.
So in your case it will automatically pick up src/main/java
(standard maven source location) and the two that you have configured the build-helper-maven-plugin to add, src-gen/gen/java
& src/extra/java
.
All you need to do is simply remove the includes
section and your build should work. So the maven-compiler-plugin in your pom would simply be:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
...
Kilátó
Updated on June 05, 2022Comments
-
Kilátó almost 2 years
I red more discussion about how to add more source folders to MAVEN and I choose to use the MOJO's build-helper-maven-plugin plugin. The pom.xml looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my.maven.tests</groupId> <artifactId>helper</artifactId> <version>1.0</version> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>add-gen-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src-gen/gen/java</source> </sources> </configuration> </execution> <execution> <id>add-extra-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/extra/java</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> <includes> <include>src/main/java/**/*.java</include> <include>src-gen/gen/java/**/*.java</include> <include>src/extra/java/**/*.java</include> </includes> </configuration> </plugin> </plugins> </build> </project>
Using the command
mvn clean compile
the build finishes fine, without errors, but no classes are generated.I am sure I made something wrong but I cannot figure out.