如何从Maven Shaded插件中删除特定文件

时间:2017-09-04 15:20:48

标签: java maven

我正在尝试使用maven-shade-plugin生成Uber Jar,我想从阴影jar中排除一些资源并包含一些指定的工件。但是下面的排除资源与它捆绑在一起。

    <dependency>
        <groupId>com.sample.auto</groupId>
        <artifactId>sample</artifactId>
        <version>1.5.0</version>
    </dependency>

    <dependency>
        <groupId>com.sample.manual</groupId>
        <artifactId>sample-manual</artifactId>
        <version>1.5.0</version>
    </dependency>

<profile>
            <id>Distribute</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>2.3</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <transformers>
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        </transformer>
                                    </transformers>
                                    <filters>
                                        <filter>
                                            <artifact>*:*</artifact>
                                            <excludes>
                                                <exclude>META-INF/*.SF</exclude>
                                                <exclude>META-INF/*.DSA</exclude>
                                                <exclude>META-INF/*.RSA</exclude>
                                                <exclude>META-INF/LICENSE</exclude>
                                                <exclude>LICENSE</exclude>
                                                <exclude>com/myproject/auto/**</exclude>
                                                <exclude>org/**</exclude>
                                                <exclude>/*.png</exclude>
                                                <exclude>/*.html</exclude>
                                                <exclude>/*.jpeg</exclude>
                                                <exclude>com/google/common/**</exclude>
                                            </excludes>
                                        </filter>
                                    </filters>
                                    <shadedArtifactAttached>true</shadedArtifactAttached>
                                    <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

此外,我需要将com.sample.auto相关工件仅包含在我的超级罐中。请让我知道我犯了什么错误。

1 个答案:

答案 0 :(得分:0)

找到了从Uber Jar中排除包含工件的简单方法。由于上面提到的@nullpointer可以使用过滤器来做到这一点。

<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>
                                    <artifactSet>
                                        <excludes>
                                            <exclude>META-INF/*.SF</exclude>
                                            <exclude>META-INF/*.DSA</exclude>
                                            <exclude>META-INF/*.RSA</exclude>
                                            <exclude>META-INF/LICENSE</exclude>
                                            <exclude>LICENSE</exclude>
                                            <exclude>*:*</exclude> // exclude all artifacts
                                             <exclude>com.sample.manual:*</exclude> // exclude specific artifact

                                        </excludes>
                                        <includes>
                                            <include>com.sample.auto:*</include> //include only com.sample.auto
                                        </includes>
                                    </artifactSet>
                                    <transformers>
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                                        <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        </transformer>
                                    </transformers>

                                    <shadedArtifactAttached>true</shadedArtifactAttached>
                                    <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                                    <minimizeJar>true</minimizeJar>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>