0

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

Chks
  • 23
  • 7
  • Maven is a build tool and not a deploy tool... – khmarbaise Sep 02 '18 at 15:44
  • @khmarbaise Yes, I do agree. Having said that and despite the fact that Maven is a build tool, would it be possible to use maven plugins instead maven-ant-tasks? – Chks Sep 02 '18 at 19:30

1 Answers1

1

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
Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59