我正在使用maven程序集插件来打包我的项目的发行版,其中包含带有依赖项jar的lib文件夹,带有资源的config文件夹以及包含项目类文件的jar文件。我需要从lib文件夹中的一个依赖罐中排除软件包。
assembly插件具有解压缩依赖项jar的选项,如果使用了该选项,则可以像下面这样用Assembly.xml排除软件包:
<assembly>
<formats>
<format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>./${project.build.finalName}/lib</outputDirectory>
<scope>runtime</scope>
<unpackOptions>
<excludes>
<exclude>**/excludedpackage/**<exclude>
</excludes>
</unpackOptions>
</dependencySet>
</dependencySets>
</assembly>
我的问题是,如何在不使用拆包的情况下将包从依赖项jar中排除(即将所有依赖项打包为jar)?理想情况下,我希望可以使用程序集插件完成解决方案-如果无法实现,那么最简单的方法就是实现我想做的事情?
最佳答案
我认为在解压缩并过滤JAR之后,您不能重新打包它。您可以在Maven Assembly Plugin JIRA提交增强请求。
一个(复杂的)解决方法是使用maven-dependency-plugin
将要从中排除某些项目的依赖项unpack,然后使用maven-jar-plugin
再次将类排除在新JAR中的包之外,最后使用<files>
声明maven-assembly-plugin
的ojit_code元素那个特殊的依赖性。
示例配置为
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<includeArtifactIds><!-- include here the dependency you want to exclude something from --></includeArtifactIds>
<outputDirectory>${project.build.directory}/unpack/temp</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>repack</id>
<goals>
<goal>jar</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<classesDirectory>${project.build.directory}/unpack/temp</classesDirectory>
<excludes>
<exclude>**/excludedpackage/**</exclude>
</excludes>
<outputDirectory>${project.build.directory}/unpack</outputDirectory>
<finalName>wonderful-library-repackaged</finalName> <!-- give a proper name here -->
</configuration>
</execution>
</executions>
</plugin>
然后,在程序集配置中,您将具有:
<files>
<file>
<source>${project.build.directory}/unpack/wonderful-library-repackaged.jar</source>
<outputDirectory>/${project.build.finalName}/lib</outputDirectory>
</file>
</files>