maven-shade-plugin插件使用的注意事项

老项目(非SpringBoot)使用Spring+Dubbo,主要xml+部分注解配置。
通过com.alibaba.dubbo.container.Main.main(args);启动容器,使用maven-shade-plugin插件打包。
需要注意的是,如果自定义了Dubbo或Sentinel的SPI扩展,META-INF/services会覆盖同名文件,可能导致某些扩展未生效,需要手动在xml中配置,注意AppendingTransformer的配置。

参考:
http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html
https://github.com/alibaba/Sentinel/issues/1013

<build>
        <finalName>demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>**/Log4j2Plugins.dat</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/com.alibaba.csp.sentinel.init.InitFunc</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/com.alibaba.csp.sentinel.slotchain.SlotChainBuilder</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/com.alibaba.csp.sentinel.command.CommandHandler</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/com.alibaba.csp.sentinel.transport.HeartbeatSender</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/com.alibaba.csp.sentinel.transport.CommandCenter</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                                </transformer>
                            </transformers>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
posted @ 2020-07-26 22:28  cdfive  阅读(2371)  评论(0编辑  收藏  举报