有没有办法在maven中捕获用户输入并将其分配给maven属性? 是否有方法暂停maven执行流以提供命令提示,以便用户可以输入文本 然后,我希望提供的文本存储在maven属性中 如果用户输入可以被屏蔽,那将是一个额外的好处
这对于避免在pom中存储密码非常有用有没有办法在maven中捕获用户输入并将其分配给maven属性? 是否有方法暂停maven执行流以提供命令提示,以便用户可以输入文本 然后,我希望提供的文本存储在maven属性中 如果用户输入可以被屏蔽,那将是一个额外的好处,maven,plugins,input,maven-plugin,command-prompt,Maven,Plugins,Input,Maven Plugin,Command Prompt,这对于避免在pom中存储密码非常有用 非常感谢如果您在pom中添加这样的属性: <properties> <db.password></db.password> </properties> 但它不像命令提示符那样具有交互性。您可以使用maven antrun插件捕获用户输入。 下面的示例显示如何询问当前用户新的项目版本 <profile> <id>change-version</id&
非常感谢如果您在pom中添加这样的属性:
<properties>
<db.password></db.password>
</properties>
但它不像命令提示符那样具有交互性。您可以使用maven antrun插件捕获用户输入。 下面的示例显示如何询问当前用户新的项目版本
<profile>
<id>change-version</id>
<build>
<defaultGoal>validate</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>catch-new-version</id>
<goals>
<goal>run</goal>
</goals>
<phase>validate</phase>
<configuration>
<target>
<!-- == catch new version in a prompt == -->
<input
message="Please enter the new SNAPSHOT version (current is '${project.version}'): "
addproperty="new-user-version" />
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>set-new-version</id>
<goals>
<goal>set</goal>
</goals>
<phase>validate</phase>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${new-user-version}</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
一些解释:
- -N-选项允许不在子项目中重复出现
- 使用 org.apache.ant:ant:1.8.4避免
- 使用maven 3.0.4
- 文件:
$ mvn -Ddb.password="DonaldDuck" install
<profile>
<id>change-version</id>
<build>
<defaultGoal>validate</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>catch-new-version</id>
<goals>
<goal>run</goal>
</goals>
<phase>validate</phase>
<configuration>
<target>
<!-- == catch new version in a prompt == -->
<input
message="Please enter the new SNAPSHOT version (current is '${project.version}'): "
addproperty="new-user-version" />
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>set-new-version</id>
<goals>
<goal>set</goal>
</goals>
<phase>validate</phase>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
<newVersion>${new-user-version}</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
mvn -N -P change-version