【问题标题】:Filter resources maven-shade-plugin过滤资源 maven-shade-plugin
【发布时间】:2013-04-11 10:40:45
【问题描述】:

我正在尝试过滤我的 jar 中包含的资源。我正在使用 shade-maven-plugin,这个插件将我所有依赖项的所有资源添加到我生成的 jar 中,我只想包含我的项目资源。

这是我的 pom 定义:

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <minimizeJar>true</minimizeJar>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>es.app.applet.MyApplet</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </plugin>

我尝试添加下一个过滤器以删除所有资源,然后添加另一个过滤器,仅添加我的 artifactID 资源,但它不起作用。

                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>resources/*.*</exclude>
                        </excludes>
                    </filter> <filter>
                        <artifact>my.groupId:my.artifactId</artifact>
                        <includes>
                            <include>resources/*.*</include>
                        </includes>
                    </filter>

想法?

谢谢。

【问题讨论】:

  • 看起来很公平,您的过滤器没有保留您的资源吗?

标签: maven maven-shade-plugin


【解决方案1】:

这是因为过滤器包含发生在过滤器排除之前。

使用您的代码,您将包括“my.groupId:my.artifactId” -> 资源/

但后来你排除了所有“资源/.

来自原documentation

从逻辑的角度来看,包含在排除之前处理​​, 因此可以使用包含来收集一组文件 存档然后使用排除来进一步减少集合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-09
    • 2018-08-19
    • 2014-09-05
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    相关资源
    最近更新 更多