Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在maven中捕获用户输入并将其分配给maven属性? 是否有方法暂停maven执行流以提供命令提示,以便用户可以输入文本 然后,我希望提供的文本存储在maven属性中 如果用户输入可以被屏蔽,那将是一个额外的好处_Maven_Plugins_Input_Maven Plugin_Command Prompt - Fatal编程技术网

有没有办法在maven中捕获用户输入并将其分配给maven属性? 是否有方法暂停maven执行流以提供命令提示,以便用户可以输入文本 然后,我希望提供的文本存储在maven属性中 如果用户输入可以被屏蔽,那将是一个额外的好处

有没有办法在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中存储密码非常有用


非常感谢

如果您在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
  • 文件:

用于哪些目的?通常没有办法。但作为一个例子,您可以查看Maven release Plugin或Maven-pgp-Plugin.Maven-scm-Plugin,tomcat6 Maven Plugin也可以从settings.xml文件读取(加密)密码。检查插件的常见问题和/或示例部分,因为插件之间的配置可能会有所不同。我认为这是一种更好的方法,更适合“Maven way”@Anonymous管理。此外,OP的问题中没有提到操作系统(或shell)。进程的参数通常对其他进程可见,有时对用户可见。如果要捕获密码,请参阅
$ 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