Conner McNamara
Conner McNamara

Reputation: 365

Client JAR containing maven dependencies

I'm building a service which contains a client module which is using Spring. The service which will be implementing the client does not contain spring but it has a dependency on the client which has dependencies on Spring. Ideally I would like the client to include the needed Spring dependencies in the JAR but I can't seem to figure out how to accomplish this. I've seen a few different examples of using maven-assembly-plugin but I would prefer to not have to use something other than "mvn clean package" to accomplish this.

Any help is appreciated.

Upvotes: 0

Views: 455

Answers (2)

Raghuram
Raghuram

Reputation: 52655

By binding the assembly plugin's single goal to the project's build lifecycle, you can accomplish what you want by running mvn clean package.

Cut/pasting the pom configuration to do this from the usage page of the plugin,

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2.2</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>

Of course, you would tweak either either to use a different predefined descriptor or even use a separate descriptor file.

Upvotes: 0

ptyx
ptyx

Reputation: 4164

The maven-shade-plugin allows you to build an uber-jar containing some (or all) of your dependencies. It should allow you to do what you need.

Upvotes: 2

Related Questions