views:

37

answers:

1

I have two projects, "appA" and "appB", that each depend on a third project, "common". I'm in the process of moving them from ant to maven, but I'm having some difficulty figuring out the best way to do it in maven. My folder structure looks like this:

root
+ common
+ appA
+ appB

I've been able to add a parent pom.xml to the root and have common, appA and appB as modules of this parent project to get appA and appB to build, but this is not what I want, a root pom.xml is not appropriate since appA and appB are completely unrelated projects.

I'd like appA and appB to be separate maven projects which both depend on the third common project and will build it if necessary, so that I can go into either the appA or appB folder and type "mvn package" to build appA + common or appB + common, respectively. This is how I have it set up in Ant but there may not be an appropriate parallel in maven. Any help or nudges in the right direction is greatly appreciated :)

A: 

(...) but this is not what I want, a root pom.xml is not appropriate since appA and appB are completely unrelated projects.

Then don't do it, don't use aggregation if you don't want to and just declare common as a dependency in the POM of appA and in the POM of appB. Something like this:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId>
  <artifactId>appA</artifactId>
  <packaging>jar</packaging>
  <version>X-SNAPSHOT</version>
  ...
  <dependencies>
    <dependency>
      <groupId>bar</groupId><!-- at your discretion -->
      <artifactId>common</artifactId>
      <version>Y.Z-SNAPSHOT</version>
    </dependency>
    ...
  </dependencies>
  ...
</project>

Dependencies are resolved through the local repository so you'll have to mvn install the common project first (and after any change to make them "visible").

During development, a common practice is to import dependent projects in your IDE and to configure them to depend on project inside the workspace (vs binary dependencies). This saves the install step to make changes visible. Most IDEs support this approach.

Pascal Thivent
That's how I figured it would work, but I can't figure out how to refer to the common project without it being part of a parent project somehow. Is there a way to use a relative path in the dependency? I would need to use "../common" somewhere to tell it where that project is, right?
jgor
@jgor: No, dependencies are resolved through the local repository, you'll have to run `install` on the `common` project to get it installed in the local repository.
Pascal Thivent
Thanks! I hadn't fully grasped the concept of the local repository. I at least have a simple example working now.
jgor