有没有办法在 maven 中捕获用户输入并将其分配给 maven 属性? [英] Is there a way to capture user input in maven and assign it to a maven property?

查看:25
本文介绍了有没有办法在 maven 中捕获用户输入并将其分配给 maven 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 有没有办法暂停 Maven 执行流程以提供命令提示符,以便用户可以输入文本.
  2. 然后我希望将提供的文本存储在 Maven 属性中.
  3. 如果可以屏蔽用户输入,那就太好了.

这对于避免在 pom.xml 中存储密码非常有用.

This would be really useful to avoid storing passwords in pom.

非常感谢

推荐答案

您可以使用 ma​​ven-antrun-plugin 捕捉用户输入.下面的例子展示了如何向当前用户询问新的项目版本.

You can catch a user input using maven-antrun-plugin. The following example show how ask current user the new project version.

    <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>

您可以通过调用来运行此功能:

You can run this feature by calling :

mvn -N -P change-version

一些解释:

  • The -N- option allow to not recurse into sub-projects.
  • Using org.apache.ant:ant:1.8.4 to avoid https://issues.apache.org/bugzilla/show_bug.cgi?id=51161
  • Using maven 3.0.4
  • Documentation: maven-antrun-plugin, Input Tag

这篇关于有没有办法在 maven 中捕获用户输入并将其分配给 maven 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆