前面讲到assembly在unpack和repackage的过程中不会merge相同名字的文件而是直接忽略,所以会导致一些问题,所以我们最后选择了可以通过文件merge功能的shade plugin,实现如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>executable</finalName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>Shaded</shadedClassifierName>
<shadedTestJar>true</shadedTestJar>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.cloud.....PublisherTest</mainClass>
</transformer>
<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/spring.tooling</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
不过这种方式,我需要把test class,test resouce放到main中,因为shade打包的时候不包含test相关的东西。