Is there a way to inject dependencies programatically in a maven plugin as if
they were declared in the POM itself? I only found one post discussing this
and it did not help.
Why do I want to do this?
Assume I have a fruit pom which imports a bom-pom which declares version
numbers for fruits, vegetables and other artifacts. Example:
fruit pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com</groupId>
<artifactId>foods</artifactId>
<version>10.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupid>com</groupId>
<artifactId>apple</artifactId>
<classifier>fruit</classifier>
</dependency>
<dependency>
<groupid>com</groupId>
<artifactId>orange</artifactId>
<classifier>fruit</classifier>
</dependency>
</dependencies>
food pom:
<dependencies>
<dependency>
<groupid>com</groupId>
<artifactId>apple</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>fruit</classifier>
</dependency>
<dependency>
<groupid>com</groupId>
<artifactId>orange</artifactId>
<version>2.0-SNAPSHOT</version>
<classifier>fruit</classifier>
</dependency>
<dependency>
<groupid>com</groupId>
<artifactId>artichoke</artifactId>
<version>3.0-SNAPSHOT</version>
<classifier>vegetable</classifier>
</dependency>
<dependency>
<groupid>com</groupId>
<artifactId>asparagus</artifactId>
<version>4.0-SNAPSHOT</version>
<classifier>vegetable</classifier>
</dependency>
</dependencies>
The fruit pom only needs to inject dependencies that have a classifier of
type fruit. The goal is to do this programatically so user's do not have to
edit multiple pom files when adding a new dependency.
The real use case is more complicated than this but I hope the above example
gets at the heart of the question.
I understand I can use the maven model api to read and write poms but that
seems to require an intermediate step and perhaps a second instance of maven
to be spawned in order to consume the intermediate pom. Ideally I would
like to avoid this step and inject dependencies programatically into the pom
which declares the plugin-in itself. Is this even possible or is the pom
immutable?
--
View this message in context:
http://maven.40175.n5.nabble.com/Inject-maven-dependencies-programatically-through-plug-in-tp5688342.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]