除了 src/main/java 之外,我还添加了一个 src/bootstrap 目录,我想将它包含在我的构建过程中,换句话说,我希望 maven 编译并将源代码包含在我的构建中。如何!?
src/{main,test}/
以外的目录中,如所告知的 here
您可以使用 Build Helper Plugin,例如:
<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>
注意:此解决方案只会将 java 源文件移动到 target/classes 目录,不会编译源。
将 pom.xml 更新为 -
<project>
....
<build>
<resources>
<resource>
<directory>src/main/config</directory>
</resource>
</resources>
...
</build>
...
</project>
<resource>
视为“Resource”文件夹而不是“Source”文件夹,例如它不会编译其中的 Java 源文件。
http://maven.apache.org/guides/mini/guide-using-one-source-directory.html
<build>
<sourceDirectory>../src/main/java</sourceDirectory>
也见
Maven compile with multiple src directories
对于最新的 Maven 版本 (3) 和最新版本的 Maven 编译器插件 (3.7.0),我注意到如果包含要在构建中添加的源代码的文件夹是位于 target
文件夹或其子文件夹中。
编译器 maven 插件似乎编译位于此文件夹内的任何 java 源代码,无论包含它们的目录是什么。
例如有一些(生成或没有) target/a
中的源代码,target/generated-source/foo
将被编译并添加到 outputDirectory 中:target/classes
。
您可以为构建过程添加目录,例如:
...
<resources>
<resource>
<directory>src/bootstrap</directory>
</resource>
</resources>
...
src/main/java 是默认路径,不需要在 pom.xml 中提及
target/classes
,但未编译)。这个问题是关于添加一个源目录,其中包含将被编译 到 target/classes
中的文件,而不是复制的。
不定期副业成功案例分享
buildpath
之一?因为它不适合我。 FWIW,我使用m2e
导入项目。Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:build-helper-maven-plugin:1.7:add-source (execution: add-source, phase: generate-sources)
收到此错误