You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Rémy Sanlaville <re...@gmail.com> on 2010/05/17 12:15:38 UTC

IoC applied to build tools?

Consider the following project:
P1
 ---- m1
 ---- m2
        ---- m2.1
        ---- m2.2
 ---- m3
        ---- m3.1
        ---- m3.2
        ---- m3.3
--- pom.xml

For testing, mocking, prototyping... we often want to be able to replace a
set of modules/artifacts by new modules/artifacts: for instance m1, m2.2 and
m3.3 by m1-mock, m2.2-test and m3.3-test.
It's not easy to do it: either you have to generate different artifacts with
the same name (with different behavior...) or to modify your
modules/dependencies + use of profiles which complicates the build. It's not
really what we want to do.
How do you cope with this?

A solution could be to applied IoC to maven.
Somethings like this

(P1) pom.xml

<dependencyManagement>
  <dependency ref="ref-m1"/>

  <dependency>
    <groupId>...</groupIdp>
    <artifactId>m2.1</artifactId>
  </dependency>

  <dependency ref="ref-m2.2"/>

   ...
</dependencyManagement>


<modules>
  <module ref="ref-m1"/>
  <module>m2</module>
  <module>m3</module>
</modules>

with different configurations
c1:
  <bean id="ref-m1" module="m1">
     <property name="artifactId" value="m1" />
     ...
  </bean>

  <bean id="ref-m2.2" module="m2.2">
     <property name="artifactId" value="m2.2" />
     ...
  </bean>

  <bean id="ref-m3.3"module="m3.3">
      <property name="artifactId" value="m3.3" />
     ...
  </bean>

and c2:
<!--
  <bean id="ref-m1" module="m1-mock">
     <property name="artifactId" value="m1-mock" />
     ...
  </bean>

<!-- module and artifactId value could be different for instance we just
want to replace
      the m2.2 artifact by its corresponding test artifact m2.2-test but not
the name of the module -->
  <bean id="ref-m2.2" module="m2.2">
     <property name="artifactId" value="m2.2" />
     <property name="classifier" value="test" />
     ...
  </bean>

  <bean id="ref-m3.3"module="m3.3">
      <property name="artifactId" value="m3.3" />
     <property name="classifier" value="test" />
     ...
  </bean>

What do you think about it?

Rémy