简体   繁体   English

从命令行更改Maven-shade-plugin outputFile

[英]Change maven-shade-plugin outputFile from command line

I am using the maven-shade-plugin in my pom.xml and I want to be able to dynamically set the from the command line, something like this: mvn -outputFile=C:/Users/Oscar/Desktop/MyJar.jar 我在pom.xml中使用了maven-shade-plugin,并且希望能够从命令行动态设置,例如: mvn -outputFile=C:/Users/Oscar/Desktop/MyJar.jar

I don't want to hardcode a filepath directly in the pom.xml because I don't want it in the repo. 我不想直接在pom.xml中对文件路径进行硬编码,因为我不想在回购中使用它。 And on our production server I want to be able to specify an output path for the shaded jar. 在我们的生产服务器上,我希望能够为阴影罐子指定输出路径。 And on my local development machine I want to be able to specify my own path. 在我的本地开发机器上,我希望能够指定自己的路径。

Is it possible to do something like this? 有可能做这样的事情吗?

<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>

I would suggest using a properties file to set the value, and then add the properties file to your .gitignore . 我建议使用属性文件设置值,然后将属性文件添加到.gitignore This is actually a pretty common use case, as values like this will vary across deployment environments. 实际上,这是一个非常常见的用例,因为这样的值在部署环境中会有所不同。 See this question or this article for discussion around the issue. 有关此问题的讨论,请参阅此问题本文

You can use a system property to define the value of outputFile 您可以使用系统属性来定义outputFile的值

Change the line in your pom.xml 更改pom.xml的行

<outputFile>${outputFilePath}</outputFile>

And then use the variable in command line 然后在命令行中使用变量

mvn -DoutputFilePath=C:/Users/Oscar/Desktop/MyJar.jar ...

You can define the default value in the properties of your pom.xml 您可以在pom.xmlproperties中定义默认值

<properties>
    <outputFilePath>C:/Users/Oscar/Desktop/Default/MyJar.jar</outputFilePath>
</properties>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM