在maven shade插件打包项目后,没有在目标中找到阴影jar

时间:2018-04-17 05:34:42

标签: java maven-shade-plugin

在运行mvn package:shade shade时,日志中包含以下内容:使用XYZ-shaded.jar替换XYZ.jar 但在我的目标目录中,我找不到阴影jar enter image description here

这是关于maven shade的pom

enter image description here

尝试后,这个pom帮助了我

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.1.1</version>
    <configuration>
        <filters>
            <filter>
                <artifact>*:*</artifact>
                <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                </excludes>
            </filter>
        </filters>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>shaded</shadedClassifierName>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>reference.conf</resource>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Main-Class>akkaexample.Akkmain</Main-Class>
                        </manifestEntries>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>akkaexample.Akkmain</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>

1 个答案:

答案 0 :(得分:2)

检查输出jar文件是否为阴影?

Shade插件可能在这里替换原始文件,意味着用阴影版本覆盖它。

如果你希望最后得到两个jar文件(阴影和无阴影),你可能需要将shadedArtifactAttached属性设置为true

  

定义阴影工件是否应作为分类器附加到原始工件。如果为false,则阴影jar将成为项目的主要工件

请参阅Maven Shade Mojo Documentation.