繁体   English   中英

如何使用maven程序集插件从依赖jar中排除一个包?

[英]How to use maven assembly plugin to exclude a package from dependency jar?

我正在使用maven程序集插件来打包我的项目的发行版,其中包含一个带有依赖项jars的lib文件夹,一个包含资源的配置文件夹和包含项目类文件的jar文件。 我需要从lib文件夹中的一个依赖项jar中排除一个包。

程序集插件有一个解包依赖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>

我的问题是,如何在不使用unpack的情况下从依赖jar中排除一个包(即将所有依赖项打包为jar)? 理想情况下,我想要一个可以使用程序集插件完成的解决方案 - 如果不可能,那么实现我想要做的最简单的方法是什么?

在解压缩和过滤后,我认为你不能重新包装JAR。 您可以在Maven Assembly Plugin JIRA上提交增强请求。


一个(复杂的)解决方法是使用maven-dependency-plugin 解压缩你要从中排除某些内容的项目的依赖项,然后使用maven-jar-plugin再次对类进行jar ,排除新JAR中的包,最后为该特定依赖项声明maven-assembly-plugin<files>元素。

样本配置将是

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM