tags:

views:

30

answers:

3

I have a library A, which depends on the libraries B and C. I unpack the libraries classes of B and C into the jar for library A using the maven-dependency-plugin (see below).

Now, when a library D uses library A, library D can access all the classes of A, B and C. However, I want D only to depend on A but not on the transitive dependencies B and C.

alt text

I know this can be achieved by manually excluding B and C for the dependency A-D but I would like to somehow declare in A that B and C are not to be made known to modules using A.

        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack-dependencies</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
+3  A: 

I think you can mark the dependency with the scope "provided" so the dependent project will assume that the jar's are already "provided". Normally they are provided by the container, in your case you "provided" them in dependency A.

In any case modules dependent on A will ignore the dependencies B and C.

Peter Tillemans
Thanks! This scope works perfectly in my case!
mxro
+2  A: 

First option, use dependency:unpack instead of dependency:unpack-dependencies and thus list B and C in the plugin configuration instead of declaring them as dependencies (so they will be unknown to D).

Second option, declare B and C as dependencies of A with a provided scope as suggested by Peter (see Transitive Dependencies‎) and you won't "see" them in D.

Pascal Thivent
Thanks! Dependency Unpack looks like a good option. Thanks for the link to the Maven documentation! I think the description of "provided" is a little bit misleading. But this scope precisely does the job in the case shown above.
mxro
A: 

I did something similar this week using the maven-shade-plugin to create an uber jar. However when I added the uber jar as a dependency to another project the underlying jars were transitively added.
To fix it I had to mark the dependencies of the uber-jar as <optional>true</optional> in its pom, and reinstall the uber-jar.
See http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

crowne