daydreamer
daydreamer

Reputation: 91949

maven: including selected dependencies for single jar

I have a maven module, which depends on two other modules

   <dependencies>
        <dependency>
            <groupId>com.org.me_services.federated_services</groupId>
            <artifactId>ifs</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.org.me_services.inventory</groupId>
            <artifactId>converter</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

I want both of these dependencies to be included in jar created by this module. I tried maven shade plugin like

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <finalName>business-${artifactId}-${version}</finalName>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>

but this bundles every depedency (even the framework). Is there a way to be selective about which dependencies I want to include in final jar?

Upvotes: 1

Views: 1048

Answers (1)

mavarazy
mavarazy

Reputation: 7735

You can specify exclude for shade artifacts:

http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet

  <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>
          <artifactSet>
            <excludes>
              <exclude>classworlds:classworlds</exclude>
              <exclude>junit:junit</exclude>
              <exclude>jmock:*</exclude>
              <exclude>*:xml-apis</exclude>
              <exclude>org.apache.maven:lib:tests</exclude>
              <exclude>log4j:log4j:jar:</exclude>
            </excludes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>

Upvotes: 1

Related Questions