maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carson Black <carson.r.bl...@gmail.com>
Subject inject dependencies programatically in maven
Date Sat, 05 May 2012 23:48:24 GMT
Is there a way to inject dependencies programatically in a maven plugin as
if they were declared in the POM itself?

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?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message