ideamaven打包模块项目依赖出现问题记录

情况:项目开发有四个mavenmodule模块,分别为ABCD,其中ABD打包后均为jar,C为springboot项目结构,而ABC均依赖D模块,在使用maven package打包发现,C项目能把D项目作为依赖打包进来,而AB均只打包了各自文件并未打包C,导致运行AB时出现错误

出现错误原因:使用maven默认的package命令构建的jar包中只包括了工程自身的class文件,并没有包括依赖的jar包

解决方案:修改原来maven的打包工具,使用maven插件,下面配置能将maven所有依赖均打包进来,故为:

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>

                <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>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>core.OffLineRecommendHandle</mainClass>
                                </transformer>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>reference.conf</resource>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


猜你喜欢

转载自blog.csdn.net/hzs33/article/details/80697401