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

Andy W

I'm using maven assembly plugin to package a distribution of my project that contains a lib folder with dependency jars, a config folder with resources and the jar file containing the project class files. I need to exclude a package from one of the dependency jars in the lib folder.

The assembly plugin has an option to unpack dependency jars, and if this is used then you can exclude a package with assembly.xml like so:

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

My question is, how can I exclude a package from a dependency jar without using unpack (i.e. keeping all dependencies packed as jars)? Ideally I'd like a solution that can be done using assembly plugin - if that's not possible what is the simplest way to achieve what I want to do?

Tunaki

I don't think you can repack the JAR after it has been unpacked and filtered. You could submit an enhancement-request at the Maven Assembly Plugin JIRA.


A (complicated) workaround would be to use the maven-dependency-plugin to unpack the project's dependency that you want to exclude something from, then use the maven-jar-plugin to jar the classes again excluding a package in a new JAR and finally declare a <files> element for the maven-assembly-plugin for that particular dependency.

A sample configuration would be

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

Then in your assembly configuration, you would have:

<files>
    <file>
        <source>${project.build.directory}/unpack/wonderful-library-repackaged.jar</source>
        <outputDirectory>/${project.build.finalName}/lib</outputDirectory>
    </file>
</files>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

How to exclude a package from a jar (with maven)

From Dev

maven-dependency-plugin: exclude .jar files

From Dev

How to include package.jar with maven-assembly-plugin

From Dev

How to exclude project dependency from classpath used by maven plugin

From Dev

how to use maven bundle plugin to exclude package out of bundle

From Dev

Maven: exclude dependency from shade plugin

From Dev

maven exclude plugin in dependency

From Dev

How to exclude a direct dependency of a Maven Plugin

From Dev

Use local jar as artifact in maven dependency plugin?

From Dev

Package jar from Nexus using Assembly plugin

From Dev

How to exclude transitive dependency in Sbt ( in context of assembly plugin )?

From Dev

How do I exclude java files from a jar in maven-jar-plugin?

From Dev

Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)

From Dev

How can I exclude some packages (within a JAR) from a Maven dependency?

From Dev

How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

From Dev

Gradle: How to exclude a particular package from a jar?

From Dev

How to really & fully exclude a package from a jar?

From Dev

maven-assembly-plugin: How to use appendAssemblyId

From Dev

maven-assembly-plugin: How to use appendAssemblyId

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

How to add files from webapp directory to jar using Maven Assembly plugin?

From Dev

How to include resource file into osgi bundle from jar dependency with bnd/maven-bundle-plugin?

From Dev

How to include resource file into osgi bundle from jar dependency with bnd/maven-bundle-plugin?

From Dev

How to exclude package from scoverage in maven

From Dev

Exclude resources from dependency jar

From Dev

How to configure a manifest file of a jar file by using the maven assembly plugin?

From Dev

Exclude Package From Gradle Dependency

From Dev

Exclude file directory, by assembly plugin MAVEN

Related Related

  1. 1

    Maven assembly or shade plugin - How to exclude sources from jar?

  2. 2

    How to exclude a package from a jar (with maven)

  3. 3

    maven-dependency-plugin: exclude .jar files

  4. 4

    How to include package.jar with maven-assembly-plugin

  5. 5

    How to exclude project dependency from classpath used by maven plugin

  6. 6

    how to use maven bundle plugin to exclude package out of bundle

  7. 7

    Maven: exclude dependency from shade plugin

  8. 8

    maven exclude plugin in dependency

  9. 9

    How to exclude a direct dependency of a Maven Plugin

  10. 10

    Use local jar as artifact in maven dependency plugin?

  11. 11

    Package jar from Nexus using Assembly plugin

  12. 12

    How to exclude transitive dependency in Sbt ( in context of assembly plugin )?

  13. 13

    How do I exclude java files from a jar in maven-jar-plugin?

  14. 14

    Gradle: How to exclude javax.realtime package from JScience jar dependency (Multiple dex define)

  15. 15

    How can I exclude some packages (within a JAR) from a Maven dependency?

  16. 16

    How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

  17. 17

    Gradle: How to exclude a particular package from a jar?

  18. 18

    How to really & fully exclude a package from a jar?

  19. 19

    maven-assembly-plugin: How to use appendAssemblyId

  20. 20

    maven-assembly-plugin: How to use appendAssemblyId

  21. 21

    Maven - How to exclude dependencies from generated JAR

  22. 22

    How to add files from webapp directory to jar using Maven Assembly plugin?

  23. 23

    How to include resource file into osgi bundle from jar dependency with bnd/maven-bundle-plugin?

  24. 24

    How to include resource file into osgi bundle from jar dependency with bnd/maven-bundle-plugin?

  25. 25

    How to exclude package from scoverage in maven

  26. 26

    Exclude resources from dependency jar

  27. 27

    How to configure a manifest file of a jar file by using the maven assembly plugin?

  28. 28

    Exclude Package From Gradle Dependency

  29. 29

    Exclude file directory, by assembly plugin MAVEN

HotTag

Archive