1

I'm trying to exclude a package in the jar(maven dependency) by editing pom.xml

So I tried some ways that adding tag in the , using maven-shade-plugin, and using maven-jar-plugin. But it didn't work. Package in the jar still exists.

Here're codes I tried. Thanks. artifact is jar name, com.domain.package is package to delete form jar.

<!-- first trial -->
<dependencies>
  <dependency>
    <groupId>Group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/artifact.jar</systemPath>

    <exclusions>
      <exclusion>
     <groupId>com.domain.package</groupId>
     <artifactId>package</artifactId>
      </exclusion>
    </exclusions>
   </dependency>
</dependencies>

<!-- second trial -->
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-shade-plugin</artifactId>
   <version>3.2.1</version>
   <executions>
      <execution>
         <phase>package</phase>
         <goals>
            <goal>shade</goal>
         </goals>
         <configuration>
            <artifactSet>
               <excludes>                            
                  <exclude>artifact:com.domain.package</exclude>
               </excludes>
            </artifactSet>
         </configuration>
      </execution>
   </executions>
</plugin>

<!-- third trial -->
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <version>2.4</version>
   <executions>
      <execution>
         <id>artifact</id>
         <phase>package</phase>
         <goals>
            <goal>jar</goal>
         </goals>
         <configuration>
            <excludes>
               <exclude>**/com/domain/package/*</exclude>
            </excludes>
         </configuration>
      </execution>
   </executions>
</plugin>
zzangs33
  • 197
  • 1
  • 15
  • Hi Refer below the stackoverflow link. https://stackoverflow.com/questions/9753323/how-to-exclude-a-set-of-packages-from-maven-build-jar – Sambit Mar 25 '19 at 09:27

1 Answers1

0

You can define configuration in your maven jar plugin execution to exclude and include files.

<configuration>
          <includes>
            <include>**/service/*</include>
          </includes>

https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html

Adnan Khan
  • 861
  • 5
  • 5