3

In my project's pom.xml I have the following dependency:

<dependency>
    <groupId>com.my.library</groupId>
    <artifactId>MyLib</artifactId>
    <version>1.0</version>
    <type>jar</type>
</dependency>

<dependency>
  ...
</dependency>

I would like to have my project's final built jar including the classes of above com.my.library:MyLib dependency, so I used maven-shade-plugin in the following way:

<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>com.my.library:MyLib</artifact>
                   <includes>
                       <include>com/my/library/**</include>
                   </includes>
                 </filter>
              </filters>
           </configuration>
        </execution>
     </executions>
</plugin>

Then, I run mvn clean install , my project was built successfully.

But when I check the content of MyProject.jar under target/ directory, it doesn't contain classes from com.my.library:MyLib dependency ,why? Where am I wrong with maven-shade-plugin ?

user842225
  • 5,445
  • 15
  • 69
  • 119
  • What are you using includes? Why not starting without any include/exclude and afterwards exclude things which should not be part of the resulting jar. – khmarbaise Jul 19 '14 at 13:43
  • @khmarbaise , because my big project has used quite many dependencies, I only want to include ONE dependency's classes in final jar, that's why I use includes instead of excludes. – user842225 Jul 19 '14 at 15:49
  • @user842225: I agree that you shouldn't have to manually exclude the libraries one by one, but khmarbaise does have a point. Try it like that first to see if it gets included at all and then investigate further (and check my answer). – carlspring Jul 23 '14 at 11:47

2 Answers2

1

Define an <artifactSet>:

<artifactSet>
    <includes>
        <include>com.my.library:MyLib</include>
    </includes>
</artifactSet>

And try removing the <artifact/> from the <filters/>. This should do it.

carlspring
  • 31,231
  • 29
  • 115
  • 197
0

change pattern to

<includes>
    <include>com/my/library/**.class</include>
</includes>
jmj
  • 237,923
  • 42
  • 401
  • 438