How can I exclude certain packages (in JARs) from Maven dependency?

I am depending on a library in my Maven project and I found that the JAR library contains some packages that cause my application to fail. I believe the library should work if I can somehow exclude these packages, but I would like to do it through Maven rather than hacking the JAR file myself. Is there a way to do this with Maven?

+3


source to share


1 answer


You can take a look maven-shade-plugin

. An example is shown in the official docs .



<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <filters>
            <filter>
              <artifact>junit:junit</artifact>
              <includes>
                <include>junit/framework/**</include>
                <include>org/junit/**</include>
              </includes>
              <excludes>
                <exclude>org/junit/experimental/**</exclude>
                <exclude>org/junit/runners/**</exclude>
              </excludes>
            </filter>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>

      

+3


source







All Articles