首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从命令行更改maven-shade-plugin outputFile

从命令行更改maven-shade-plugin outputFile
EN

Stack Overflow用户
提问于 2018-03-27 04:52:23
回答 2查看 452关注 0票数 0

我在我的pom.xml中使用了maven-shade-plugin,我希望能够从命令行动态设置,如下所示:mvn -outputFile=C:/Users/Oscar/Desktop/MyJar.jar

我不想直接在pom.xml中对文件路径进行硬编码,因为我不希望它出现在代码库中。在我们的生产服务器上,我希望能够为带阴影的jar指定输出路径。在我的本地开发机器上,我希望能够指定我自己的路径。

有可能做这样的事情吗?

代码语言:javascript
复制
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <relocations>
                            <relocation>
                                <pattern>com.zaxxer.hikari</pattern>
                                <shadedPattern>io.github.hornta.lib.hikari</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>com.google.gson</pattern>
                                <shadedPattern>io.github.hornta.lib.gson</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>org.slf4j</pattern>
                                <shadedPattern>io.github.hornta.lib.slf4j</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>org.flywaydb.core</pattern>
                                <shadedPattern>io.github.hornta.lib.flywaydb</shadedPattern>
                            </relocation>
                        </relocations>
                       <outputFile>I NEED TO SET THIS PATH FROM COMMAND LINE(not having it in the repo)</outputFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>
EN

回答 2

Stack Overflow用户

发布于 2018-03-27 05:01:34

我建议使用属性文件来设置值,然后将属性文件添加到.gitignore中。这实际上是一个非常常见的用例,因为这样的值在不同的部署环境中会有所不同。有关此问题的讨论,请参阅this questionthis article

票数 0
EN

Stack Overflow用户

发布于 2018-03-27 05:02:13

您可以使用系统属性来定义outputFile的值

更改pom.xml中的行

代码语言:javascript
复制
<outputFile>${outputFilePath}</outputFile>

然后在命令行中使用变量

代码语言:javascript
复制
mvn -DoutputFilePath=C:/Users/Oscar/Desktop/MyJar.jar ...

您可以在pom.xmlproperties中定义缺省值

代码语言:javascript
复制
<properties>
    <outputFilePath>C:/Users/Oscar/Desktop/Default/MyJar.jar</outputFilePath>
</properties>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49500408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档