Maven:为什么在生成eclipse项目时通过构建助手添加测试源不起作用? [英] Maven: Why does adding test source via build helper not work when generating eclipse project?
问题描述
我们的maven pom.xml指定在激活某个配置文件(此处为java8)时添加其他源和test-source文件夹。 pom的相应部分如下所示
Our maven pom.xml specifies to add an additional source and test-source folder if a certain profile (here "java8") is activated. The corresponding part of the pom looks like the following
<profile>
<id>java8</id>
....
<build>
<plugins>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals><goal>add-test-source</goal></goals>
<configuration>
<sources>
<source>src/test/java8</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
根据 http://mojo.codehaus.org/build-helper-maven-plugin/usage.html 这似乎是正确的规范。
According to http://mojo.codehaus.org/build-helper-maven-plugin/usage.html this appears to be the correct specification.
运行 mvm install -P java8
我看到其他测试按预期执行。
Running mvm install -P java8
I see that the additional tests are performed as expected.
然而,运行 mvm eclipse:eclipse -P java8
额外的测试源文件夹没有出现在eclipse中 .classpath
。
However, running mvm eclipse:eclipse -P java8
the additional test source folder does not appear in eclipse .classpath
.
问题:如何配置maven以将测试源文件夹添加到eclipse配置?是以上行为是一个错误还是错误配置?
Question: How do I have to configure maven to add the test source folder to the eclipse configuration? Is the above behavior a bug or a misconfiguration?
推荐答案
花了一些时间试验这个,我可以给出一个部分答案我自己的问题(希望节省其他开发人员的时间):
如果使用
<phase>generate-sources</phase>
<goals><goal>add-test-source</goal></goals>
而不是
<phase>generate-test-sources</phase>
<goals><goal>add-test-source</goal></goals>
然后将测试源文件夹添加到eclipse .classpath(并将其添加为测试文件夹)。即我现在在不同的阶段执行add-test-source。
then the test source folder is added to the eclipse .classpath (and it is added as a test folder). I.e. I am executing "add-test-source" in a different phase now.
换句话说,个人资料看起来像这样:
In other words the profile looks like this:
<profile>
<id>java8</id>
....
<build>
<plugins>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals><goal>add-test-source</goal></goals>
<configuration>
<sources>
<source>src/test/java8</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
这看起来像是一种解决方法。它仍然与 http://mojo.codehaus.org/build上的规范相矛盾-helper-maven-plugin / usage.html
This looks like a "workaround". It still contradicts the specification on http://mojo.codehaus.org/build-helper-maven-plugin/usage.html
这篇关于Maven:为什么在生成eclipse项目时通过构建助手添加测试源不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!