Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Get Specific Classes

Is there a way that I can get maven to only include specific .class files when importing dependencies into uber jar (shade). I'm looking for a way to get files that contain "Client" in their name to be pulled out of the dependency jars and added to the final jar. Any help would be wonderful.

like image 586
sinisterrook Avatar asked Sep 08 '15 18:09

sinisterrook


Video Answer


2 Answers

You should be able to use the maven-dependency-plugin like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId><!--dependency groupId--></groupId>
                                <artifactId><!--dependency artifactId--></artifactId>
                                <version><!--depedency version--></version>
                                <includes>**/*Client*.java</includes>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
like image 192
Andrew Mairose Avatar answered Sep 29 '22 16:09

Andrew Mairose


If you are using the Maven Shade Plugin, you can a filter, which will allow you to filter which artifacts get shaded, but as well as which classes to exclude or include.

Here's the example they provide:

<filters>
  <filter>
    <artifact>junit:junit</artifact>
    <includes>
      <include>org/junit/**</include>
    </includes>
    <excludes>
      <exclude>org/junit/experimental/**</exclude>
    </excludes>
  </filter>
</filters>
like image 26
Larry Shatzer Avatar answered Sep 29 '22 16:09

Larry Shatzer