从 maven 依赖项(webjars)中排除资源包

Exclude resource package from maven dependency (webjars)

我的 pom 有依赖性:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>extjs</artifactId>
    <version>6.0.0</version>
</dependency>

将我的项目构建到 war 后,我收到了一个超过 200MB 的包。 是否有可能排除包

/webjars/extjs/6.0.0/build/examples/

从这个依赖?我该怎么做?

我尝试使用 shade 插件,但它不起作用,同样在 war 插件配置中:

<configuration>
   <packagingExcludes>
         /webjars/extjs/${extjs.version}/build/examples/
   </packagingExcludes>
</configuration>

无效。

请查看 this 页面。它讨论了如何通过排除不必要的内容来缩小 webjar。

您可以使用 maven-assembly-plugin 并在 dependencySet. The following question 中使用 exclude 提供更多背景信息。

感谢 Dark Knight 我找到了适合我的解决方案:

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>extjs</artifactId>
        <version>${extjs.version}</version>
        <scope>provided</scope>
    </dependency>
...

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                    </manifest>
                </archive>
                <webResources>
                    <resource>
                        <directory>${project.build.directory}\extjs\META-INF\resources</directory>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack-jar</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>org.webjars</groupId>
                                <artifactId>extjs</artifactId>
                                <version>${extjs.version}</version>
                                <type>jar</type>
                                <destFileName>extjs-dependency</destFileName>
                                <includes>
                                    META-INF/resources/webjars/extjs/${extjs.version}/build/*.*,
                                    META-INF/resources/webjars/extjs/${extjs.version}/build/classic/**/*.*,
                                    META-INF/resources/webjars/extjs/${extjs.version}/build/packages/**/*.*
                                </includes>
                                <outputDirectory>
                                    ${project.build.directory}/extjs
                                </outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>