maven之使用 MOJO build-helper-maven-plugin 将更多源文件夹添加到 MAVEN
我对如何向 MAVEN 添加更多源文件夹进行了更多讨论,并选择使用 MOJO 的 build-helper-maven-plugin 插件。 pom.xml 如下所示:
<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>
使用命令 mvn clean compile 构建顺利完成,没有错误,但没有生成任何类。
我确定我做错了什么,但我想不通。
请您参考如下方法:
问题是您的 maven-compiler-plugin 的 includes 配置。 maven-compiler-plugin 将自动获取项目中配置的所有源文件夹——您无需通过 includes 标签定义它们。
所以在你的情况下,它会自动选择 src/main/java (标准的 maven 源代码位置)和你配置了 build-helper-maven-plugin 添加的两个,src-gen/gen/java & src/extra/java.
您需要做的只是删除 includes 部分,您的构建应该可以正常工作。因此,您的 pom 中的 maven-compiler-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>
</configuration>
</plugin>
...
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。



