Maven Execution Prompt Password

345 views Asked by At

I have Maven to copy files to the remote server, my code snippet is below

<scp trust="true" file="myfile.txt" todir="myuser:mypassword@myserver:/remotedir">
<sshexec trust="true" failonerror="true" host="myserver" 
 username="myuser" password="mypassword" ....>

Is there a way to avoid hard-coding password? Would like to have a prompt while executing mvn

1

There are 1 answers

0
Roland Weisleder On BEST ANSWER

I assume that you use the maven-antrun-plugin because this snippet looks more like an ant script.

As described in this answer you can pass maven properties to the maven-antrun-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
                <target>
                    <property name="antProperty" value="${my.custom.property}"/>
                    <echo message="Custom Ant Property is: ${antProperty}"/>
                    <echoproperties />
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>

You can now pass the property value via command line to the maven build:

mvn compile -Dmy.custom.property=hello