maven - 使用 build-helper-maven-plugin 和 multi module 跳过测试

标签 maven surefire

我将 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 不会执行测试。

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

[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

知道如何使这项工作成功吗?

最佳答案

尝试使用 Debug模式 (-X) 启动 mvn 以查看 surefire 使用的属性对于您的树文件夹是否正确。

关于maven - 使用 build-helper-maven-plugin 和 multi module 跳过测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9258485/

相关文章:

Maven Jenkins 插件 POM 缺少 JAR 上的依赖信息

java - 本地存储库中缺少 tools.jar 会破坏 m2eclipse

java - JAXB 绑定(bind)到 JAR 中的模式

java - 如何更改库?

Maven Surefire 并行 ='both' 的工作方式与 'methods' 相同

unit-testing - Maven surefire插件是否使用多个线程运行测试?

android - 用于搜索要在 build.gradle 中使用的 android 库的网站

java - 访问 workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\中的文件

java - 有人使用 surefire POJO 测试吗?

maven-2 - 如何用 JUnit 4 写一些东西到万无一失的日志