包括自定义源文件夹以包含在maven测试阶段

时间:2014-06-23 01:37:35

标签: maven

我们有一个遗留项目,需要我们从自定义位置提取一些自定义来源,即这样做:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals><goal>add-source</goal></goals>
            <configuration><sources><source>src/uom/java</source></sources></configuration>
        </execution>
    </executions>
</plugin>

这适用于构建和编译,但是当我们开始在/src/test/java/文件夹中添加测试时,这不会导致包含此特殊路径。在尝试编译测试用例时,mvm package失败并显示“未找到类”。我试过这个,但它不起作用:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals><goal>add-source</goal></goals>
            <configuration><sources><source>src/uom/java</source></sources></configuration>
        </execution>
        <execution>
            <id>add-test-source</id>
            <phase>generate-test-sources</phase>
            <goals><goal>add-source</goal></goals>
            <configuration><sources><source>src/uom/java</source></sources></configuration>
        </execution>
    </executions>
</plugin>

实现这一目标的正确方法是什么? documentation on this似乎没那么有用。

1 个答案:

答案 0 :(得分:0)

原来你必须改变这个:

<execution>
    <id>add-test-source</id>
    <phase>generate-test-sources</phase>
    <goals><goal>add-test-source</goal></goals> <!-- was: add--source -->
    <configuration><sources><source>src/uom/java</source></sources></configuration>
</execution>