【问题标题】:Maven Execution Prompt PasswordMaven执行提示密码
【发布时间】:2018-09-02 11:29:23
【问题描述】:

我有 Maven 将文件复制到远程服务器,我的代码 sn-p 在下面

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

有没有办法避免硬编码密码?想在执行mvn时有提示

【问题讨论】:

  • Maven 是构建工具而不是部署工具...
  • @khmarbaise 是的,我同意。话虽如此,尽管 Maven 是一个构建工具,但是否可以使用 maven 插件而不是 maven-ant-tasks?

标签: maven scp maven-antrun-plugin maven-ant-tasks


【解决方案1】:

我假设您使用 maven-antrun-plugin,因为这个 sn-p 看起来更像一个 ant 脚本。

this answer 中所述,您可以将 maven 属性传递给 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>

您现在可以通过命令行将属性值传递给 maven 构建:

mvn compile -Dmy.custom.property=hello

【讨论】:

    猜你喜欢
    • 2023-03-28
    • 2015-10-25
    • 1970-01-01
    • 2012-03-06
    • 2021-05-15
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多