5

It seems that including direct dependencies with provided scope is well understood. It also appears that including transitive dependencies with runtime scope is also easily accomplished.

But how can I include a dependency two levels of indirection away?

Example:

A --> B --> C

Where A depends on B (compile scope) and B depends on C (provided scope).

I want A to retrieve C (eg: download the jar locally), be it via assembly descriptor or maven-dependency-plugin:copy-dependencies or some other mechanism.

I've tried seemingly every combination of options for both of the aforementioned plugins. Neither approach covers this scenario. They both get B (even if B is changed to a provided dependency), and any compile scope dependencies of B, but not provided dependencies of B.

I suppose that I'm trying to do something similar to a shaded representation of my project but without unpacking dependencies.

Naturally I don't want to have to enumerate all of B's dependencies in A's pom - I'd like to retrieve (and then package) all dependencies implicitly and recursively.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Akom
  • 1,484
  • 19
  • 25

2 Answers2

1

You won't be able to do that. It is not a limitation of the maven-assembly-plugin, but the way Maven considers transitive dependencies. A transitive dependency that is of scope provided will be omitted, always (refer to this table in the documentation).

There is an open bug about this (MNG-2205) but I don't think it will be fixed anytime soon. This really is intended behaviour because provided dependencies, as per the name, as supposed to be provided at runtime.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
0

Although Tunaki is quite right, I found a workable solution that's better than nothing, using a less well-known plugin (NOTE: only works with Maven <= 3.0.X)

This specifies two dependency blocks. The first pulls in normal compile deps including transitive, it's the same as using copy-dependencies. The second block specifically mentions B in addition to the normal pom dependency declaration (unfortunately, but at least both dependency mentions are in the same pom) and requests its provided deps:

        <plugin>
            <groupId>com.github.goldin</groupId>
            <artifactId>copy-maven-plugin</artifactId>
            <version>0.2.5</version>
            <executions>
                <execution>
                    <id>get-provided-dependencies</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <targetPath>${project.build.directory}/lib</targetPath>
                                <dependencies>
                                    <dependency>
                                        <includeScope>compile</includeScope>
                                    </dependency>
                                    <dependency>
                                        <groupId>some.group</groupId>
                                        <artifactId>artifact_i_call_B</artifactId>
                                        <version>1.0</version>
                                        <includeScope>provided</includeScope>
                                    </dependency>
                                </dependencies>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Docs for this plugin may only exist in the archive at this point, not sure what happened to it: http://web.archive.org/web/20130826193436/http://evgeny-goldin.com/wiki/Copy-maven-plugin

Akom
  • 1,484
  • 19
  • 25