Martin Melka
Martin Melka

Reputation: 7789

Maven unpack-dependencies of a plugin dependency

How do I run dependency:unpack-dependencies for dependencies specified inside the <plugin> section?

I have three packages containing executables and some other stuff, let's call them parent, child and consumer. child is dependent on parent. In order to build consumer, I need to get child and all its dependencies (i.e. parent), unpack their contents and do some stuff.

What I have now works, kind of:

When the dependency on child is declared "globally" in <project>, the unpacking works as expected. However, that means that the resulting consumer package depends on child, which I do not want. The dependency has to be solely for its creation, not usage.

When I move the dependency into the <plugins><plugin> section, it is ignored by dependency:unpack-dependencies (dependency:unpack processes and unpacks it fine, but that is not transitive)

What am I missing? Thanks


Maven knows about the transitive dependency child -> parent. When I delete the whole local repository and run only this POM, parent is downloaded.


A very crude diagram of the situation below. Green artifacts are needed for creation of the final artifact (and not needed to use it afterwards), therefore dependency on them only belongs to the section. Blue artifact is needed for the usage of final artifact, therefore it has a dependency on it.

enter image description here

Upvotes: 2

Views: 470

Answers (1)

Anton Koscejev
Anton Koscejev

Reputation: 4847

Since your unpacking works as expected when you specify dependency for the whole project, perhaps you should just keep it that way. Instead of moving it to plugin dependencies you can simply instruct Maven to not include it transitively when other projects depend on your project. There are two ways to do it:

  1. Specify <scope>provided</scope> - this will tell Maven that dependency is needed for compilation, but is expected to be available at runtime by other means (such as application server providing it or you bundling it).
  2. Specify <optional>true</optional> - this will prevent dependency from being transitively resolved by other projects depending on your project. Instead, they will have to specify it explicitly, if they want it.

Upvotes: 2

Related Questions