Maven“阴影” JAR以“原始”为前缀。在文件名中
我正在使用shadeMaven2插件来构建一个捆绑在一起的所有Java依赖项的单片JAR。 pom.xml
中的相关部分非常简单:
I'm using the "shade" Maven2 plugin to build a monolithic JAR with all Java dependencies bundled together. The relevant section in pom.xml
is pretty straightforward:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-${project.version}-SHADED</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.mypackage.MyClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
但是,构建结果是奇数。看来这两个文件实际上是由这个Maven插件创建的:
However, the build results are odd. It seems that TWO files are actually created by this Maven plugin:
myartifact-1.0.0-SHADED.jar (zero bytes)
original-myartifact-1.0.0-SHADED.jar (10 MB)
JAR带有前缀original的文件已正确构建,并且运行正常。我想我可以重命名它以去掉那个前缀,并继续我的快乐方式。
The JAR file with prefix "original" is properly built, and functions just fine. I suppose I could just rename it to strip off that prefix, and go on my merry way.
然而,我非常好奇这里的阴影插件可能会发生什么。看起来原始文件是临时工作空间类型的东西,打算在进程结束时重命名,并且最终重命名根本不会完成。但是,没有明显的解释(即文件系统权限等)。有没有人见过这个?
However, I very curious as to what may be going on here with the "shade" plugin. It looks like the "original" file is temporary working space type thing, intended to be renamed at the end of the process, and that final renaming simply doesn't complete. There's no obvious explanation for that, though (i.e. filesystem permissions, etc). Has anyone ever seen this before?
Maven的构建步骤将创建jar target / artifact-version .jar
。
Maven's build steps will create the jar target/artifact-version.jar
.
然后树荫插件运行。它通常将该jar重命名为 target / original-artifact-version.jar
,并为着色的JAR指定名称 target / artifact-version.jar
。
Then the shade plugin runs. It normally renames that jar to target/original-artifact-version.jar
, and gives the shaded JAR the name target/artifact-version.jar
.
但是,您正在配置Shade插件以使用其他名称。除非有充分的理由,否则我会从您的配置中删除< finalName>
,并使用Shade插件希望为您提供的内容。
However, you're configuring the Shade plugin to use a different name. Unless there's a good reason for that, I'd remove <finalName>
from your configuration, and live with what the Shade plugin wants to give you.