批处理文件在 mvn 命令后停止执行

Mar*_*lic 8 shell command batch-file maven maven-archetype

set homepath=%userprofile%
set a=%1
set b=%2
set c=%3
set uuid=%4
set zipDirectory=%5
set pluginDirectory=%6
cd %homepath%\%a%
mvn archetype:generate -DarchetypeCatalog=file://%homepath%/.m2/repository
Run Code Online (Sandbox Code Playgroud)

到这里一切正常,然后命令行停止执行。它不打印 1,也不打印后续命令。

1
c
b
c
%uuid%
Y
cd %homepath%\%a%\%b%
mvn clean install
cd %homepath%\%a%\%b%\%b%-plugin\target
jar -xvf %zipDirectory%
cd %homepath%\%a%\%b%\%b%-plugin\target\META-INF\maven\%c%\%b%-plugin
copy pom.xml + %pluginDirectory%
cd %pluginDirectory%
rename pom.xml %b%-plugin-1.0.0.pom
Run Code Online (Sandbox Code Playgroud)

问题:有什么我不知道的关于 maven 会中断批处理的事情吗?执行带有单独编号 1 的命令不明白吗?

A_D*_*teo 8

当通过archetype从批处理文件中调用Maven创建新项目时,你应该注意执行的交互方式,即Maven会提示输入某些值或要求确认。

在您的情况下,这似乎不是您想要的行为。因此,您应该通过命令行传递目标和特定原型的一些选项generate然后通过-B标准 Maven 选项或通过-DinteractiveMode=true.

官方文档你应该通过

  • archetypeGroupId、archetypeArtifactId 和 archetypeVersion 定义了用于项目生成的原型。
  • groupId、artifactId、version 和 package 是要设置的主要属性。每个原型都需要这些属性。一些原型定义了其他属性;如果需要,请参阅相应原型的文档

因此,在您的情况下:

call mvn archetype:generate -DarchetypeCatalog=file://%homepath%/.m2/repository -B \
-DarchetypeGroupId=com.sample -DarchetypeArtifactId=artifact -DarchetypeVersion=1.0 \ 
-DgroupId=your.groupid -DartifactId=your.artifactId -Dversion=0.0.1-SNAPSHOT \
-Dsomething-else=value
Run Code Online (Sandbox Code Playgroud)

注意:\为了可读性而添加的,您实际上并不需要它