【发布时间】:2018-02-09 15:38:06
【问题描述】:
我在构建中观察到一个奇怪的行为,我对如何调查一无所知。
在我的验收测试期间,我在预集成测试阶段使用 maven-antrun-plugin 来启动之前构建的 jar。然后故障安全应该开始针对 jar 运行测试。我有一些可用的现有项目,所以我复制了配置:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>start-application</id>
<phase>pre-integration-test</phase>
<configuration>
<target>
<exec executable="cmd" dir="../" spawn="true" os="Windows 7">
<arg value="/c"/>
<arg value="launcher.bat"/>
<arg value="${project.version}"/>
</exec>
<exec executable="cmd" dir="../" spawn="true" os="Windows Server 2012 R2">
<arg value="/c"/>
<arg value="launcher.bat"/>
<arg value="${project.version}"/>
</exec>
<exec executable="./launcher.sh" dir="../" os="Linux">
<arg value="${project.version}"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</plugin>
但是,我看到了不同的行为。当我在一个适用的旧项目上执行 mvn -X clean install 时,我得到:
[INFO] Executing tasks
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]
main:
[exec] Current OS is Windows 7
[exec] Executing 'cmd' with arguments:
[exec] '/c'
[exec] 'launcher.bat'
[exec] '1.0.0-SNAPSHOT'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'cmd' with arguments:
'/c'
'launcher.bat'
'1.0.0-SNAPSHOT'
The ' characters around the executable and arguments are
not part of the command.
spawned process java.lang.ProcessImpl@5b6ba5bb
[exec] Current OS is Windows 7
[exec] This OS, Windows 7 was not found in the specified list of valid OSes: Windows Server 2012 R2
[exec] Current OS is Windows 7
[exec] This OS, Windows 7 was not found in the specified list of valid OSes: Linux
[INFO] Executed tasks
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (default) @ acceptance ---
然后测试执行..
现在在我的另一个项目中,我得到了这个:
[INFO] Executing tasks
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]
main:
[exec] Current OS is Windows 7
[exec] Executing 'cmd' with arguments:
[exec] '/c'
[exec] 'launcher.bat'
[exec] '1.0.0-SNAPSHOT'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
Execute:Java13CommandLauncher: Executing 'cmd' with arguments:
'/c'
'launcher.bat'
'1.0.0-SNAPSHOT'
The ' characters around the executable and arguments are
not part of the command.
D:\vincent\GIT\my_project\acceptance>
启动器可以工作,因为就像其他项目一样,我的 jar 会在另一个窗口中启动。但是,构建只是退出,而不是简单地使用故障安全执行测试! 日志不像其他情况那样显示生成的进程 java.lang.ProcessImpl@5b6ba5bb.. 即使它似乎确实生成了 launcher.bat。
我意识到我运行的不是完全相同版本的 antrun 插件,所以我将我的新项目降级到 1.7 以使其匹配。我在这两种情况下都使用 Java 8。
我真的没有什么想法可以调查了……有什么想法吗?
谢谢
【问题讨论】:
-
你应该指出你正在使用的 Maven 版本,同时显示工作和不工作项目的整个 pom.xml。
-
很可能launcher.bat是罪魁祸首。
-
非常感谢@EugenCovaci,你的第二条评论让我走上了正轨——为什么它失败了是一个非常愚蠢的原因!
标签: java maven maven-antrun-plugin