我在我的pom.xml中使用了maven-shade-plugin,我希望能够从命令行动态设置,如下所示:mvn -outputFile=C:/Users/Oscar/Desktop/MyJar.jar
我不想直接在pom.xml中对文件路径进行硬编码,因为我不希望它出现在代码库中。在我们的生产服务器上,我希望能够为带阴影的jar指定输出路径。在我的本地开发机器上,我希望能够指定我自己的路径。
有可能做这样的事情吗?
<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>发布于 2018-03-27 05:01:34
我建议使用属性文件来设置值,然后将属性文件添加到.gitignore中。这实际上是一个非常常见的用例,因为这样的值在不同的部署环境中会有所不同。有关此问题的讨论,请参阅this question或this article。
发布于 2018-03-27 05:02:13
您可以使用系统属性来定义outputFile的值
更改pom.xml中的行
<outputFile>${outputFilePath}</outputFile>然后在命令行中使用变量
mvn -DoutputFilePath=C:/Users/Oscar/Desktop/MyJar.jar ...您可以在pom.xml的properties中定义缺省值
<properties>
<outputFilePath>C:/Users/Oscar/Desktop/Default/MyJar.jar</outputFilePath>
</properties>https://stackoverflow.com/questions/49500408
复制相似问题