3

我将 build-helper-maven-plugin 用于具有非标准树文件夹的遗留项目。

我这样使用它:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/firstmodule/src</source>
                            <source>${basedir}/secondmodule/src</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/firstmodule/tests</source>
                            <source>${basedir}/secondmodule/tests</source>
                                                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

如果我在项目的根目录上启动 mvn install 它可以正常工作,测试通过。

但是,这个项目是一个更大项目中的一个子模块。如果我在父项目的根文件夹中启动 mvn install,maven 不会执行测试。

它似乎有效,但肯定没有检测到任何测试:

[INFO] Building MyLegacyProject
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target
[INFO] [build-helper:add-source {execution: add-source}]
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\src added.
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\src added.
[INFO] [build-helper:add-test-source {execution: add-test-source}]
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\tests added.
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\tests added.
[debug] execute contextualize
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 40 resources
[INFO] Copying 40 resources
[WARNING] While downloading com.sun.xml:saaj-impl:1.3
  This artifact has been relocated to com.sun.xml.messaging.saaj:saaj-impl:1.3.


[WARNING] While downloading javax.xml:jaxb-api:2.1
  This artifact has been relocated to javax.xml.bind:jaxb-api:2.1.


[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 752 source files to C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target\classes
[debug] execute contextualize
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 34 resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 15 source files to C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.381 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

知道如何完成这项工作吗?

4

3 回答 3

0

尝试使用调试模式 (-X) 启动 mvn 以查看 surefire 使用的属性是否适合您的树文件夹。

于 2012-02-13T20:01:29.990 回答
0

你在使用 Maven 3 吗?${basedir} 仅被 maven 3 识别(并且被 maven 2 默默忽略 :( )你如何理解 basedir 的用法?它是构建开始的 POM 的目录路径。因此,它要么是父项目目录或其模块之一,具体取决于您从哪里启动构建。在第二种情况下,路径将是错误的。我想您希望始终拥有项目根目录的路径?

于 2012-02-14T09:34:14.150 回答
0

好的,我找到了!

有人有同样的问题: https ://stackoverflow.com/a/6925096/242658

然而,这真的很难想象。

它与 build-helper-maven-plugin 无关,我不知道为什么我在单模块模式下没有这个问题。

我使用了引入 TestNG 的 powermock 和 powermock。并且使用 testng 我的测试不会被surefire检测到。所以我不得不排除testng:

<dependency>
  <groupId>org.powermock</groupId>
  <artifactId>powermock-mockito-release-full</artifactId>
  <version>1.4.9</version>
  <classifier>full</classifier>
  <exclusions>
    <exclusion>
      <artifactId>powermock-module-testng</artifactId>
      <groupId>org.powermock</groupId>
    </exclusion>
  </exclusions>
</dependency>
于 2012-02-14T13:41:06.740 回答