Maven - 在模块中运行JUnit测试套件

4

我有三个项目:

  • ParentProj(A+B的父级)
  • ProjA(是ParentProj的一个模块,包含源码)
  • ProjB(是ParentProj的一个模块,包含源码和测试)

构建顺序是:1. ParentProj,2. ProjA,3. ProjB(无法更改!)

我想告诉maven执行位于ProjB中的TestSuite。如果我使用以下命令运行构建:mvn clean -e test -Dtest=AllServiceTests,构建将失败,因为maven找不到在ProjB之前构建的ProjA中的"AllServiceTests"类。

这个问题有解决方案吗?(更改构建顺序不是解决方案)

3个回答

9
我刚刚找到了解决方案:
clean install test -Dtest=myTestSuite -DfailIfNoTests=false 

-DfailIfNoTests=false会强制Maven在ProjA中没有测试类时继续构建。

这最终解决了我的问题。


3

你有没有研究过--also-make--projects选项?

$ mvn --help

usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -am,--also-make                        If project list is specified, also
                                        build projects required by the
                                        list

 -pl,--projects <arg>                   Comma-delimited list of specified
                                        reactor projects to build instead
                                        of all projects. A project can be
                                        specified by [groupId]:artifactId
                                        or by its relative path.

我想这个可能会起作用:
mvn clean test -pl ProjB -am -Dtest=AllServiceTests

请回复并告诉我们是否有效!我非常好奇。 :)


0
最简单的解决方案是切换到ProjB目录并在那里执行命令行。

那不是解决方案,因为夜间构建是在Bamboo服务器上完成的,而不是在我的本地命令行上。;-) - L.Butz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接