plugins - Is there a way to capture user input in maven and assign it to a maven property? -
- is there way pause maven execution flow provide command prompt user can input text.
- then provided text stored in maven properties.
- if user input masked bonus.
this useful avoid storing passwords in pom.
many
you can catch user input using maven-antrun-plugin. following example show how ask current user 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 prompt == --> <input message="please enter new snapshot version (current '${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 feature calling :
mvn -n -p change-version
some explanations :
- the -n- option allow not recurse sub-projects.
- using org.apache.ant:ant:1.8.4 avoid https://issues.apache.org/bugzilla/show_bug.cgi?id=51161
- using maven 3.0.4
- documentation: maven-antrun-plugin, input tag
Comments
Post a Comment