Maven配置 指定多个源代码目录、多个资源文件目录
程序员文章站
2022-04-13 22:44:34
...
<!-- 设置多个源文件夹 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<!-- 添加主资源文件目录 -->
<execution>
<!--自定义名称,不可重复-->
<id>add-resource</id>
<!--指定绑定到生命周期-->
<phase>initialize</phase>
<!--指定指定的目标,可添加多个-->
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<!--资源文件目录,可添加多个-->
<resource>
<directory>${project.parent.basedir}/src/main/resources</directory>
<!--是否启用变量过滤-->
<filtering>true</filtering>
<!--排除的文件,可添加多个-->
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
<!-- 添加主源码目录 -->
<execution>
<id>add-source</id>
<phase>initialize</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.parent.basedir}/common/src/main/java</source>
<source>${project.basedir}/src/main/java</source>
</sources>
</configuration>
</execution>
<!-- 添加测试源码目录 -->
<execution>
<id>add-test-source</id>
<phase>initialize</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.parent.basedir}/src/test/java</source>
<source>${project.basedir}/src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
其中,common/src/main/java 是另一个模块的源码,打包后会将该目录直接打包到当前jar(war)包中。