maven 打包依赖包 pom配置

235 阅读1分钟

将依赖包一同打入
maven-assembly-plugin:存在bug 对于依赖中存在不同版本jar依赖只选取一种导致有些jar包却缺失

maven-shade-plugin:对于多版本进行整合进行打包

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <!--<exclude>org.slf4j:*</exclude>-->
<!--                                    <exclude>log4j:*</exclude>-->
                                    <!--<exclude>ch.qos.logback:*</exclude>-->
                                </excludes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <!-- Do not copy the signatures in the META-INF folder.
                                    Otherwise, this might cause SecurityExceptions when using the JAR. -->
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>*.jpg</exclude>
                                        <exclude>*.md</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <!-- Replace this with the main class of your job -->
                                    <mainClass>flow.ViewFlow</mainClass>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

打包排除部分jar包配置位置

打包排除部分文件配置位置

打包设置主类位置

希望多多支持点赞,会继续分享更多可用的知识与资源