I believe with just a few pom.xml tweaks I've managed to get something of a single source project to work with maven. It could be that a few bug fixes since Maven alpha have helped since the last time I tried but here's what I did.

1. Designed a bogus project consisting of a gui artifact that depends on a util artifact each with a single class: Main.java and Util.java respectively. Additionally the gui component uses a resource file called gui.properties. I then arranged this project into the following directory structure:

com
--------acme [pom.xml]
----------------util [Util.java, pom.xml]
----------------gui [Main.java, pom.xml]
------------------------resources [gui.properties]


2. The gui and util poms only declare the acme/pom as a parent and don't even have their own build section. The acme/pom.xml parent contains the necessary tweaks that the child poms inherit, namely inside the build section:

acme/pom.xml:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.acme</groupId>
  <artifactId>app</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Acme Application</name>
  <modules>
    <module>util</module>
    <module>gui</module>
  </modules>
  <build>
    <sourceDirectory>.</sourceDirectory>
    <resources>
      <resource>
        <directory>resources</directory>
      </resource>
    </resources>
  </build>
</project>
~

In other words the java files and resources/ directory are to be found in the same directory as the pom.xml file for any given artifact project.

3. I ran the install phase as follows:

> cd com/acme
> m2 install

which caused the target directories to be generated also at the same level as each pom - for example com/acme/util/target and com/acme/gui/ target.

4. I examined the jar files in each target directory for example "jar tvf com/acme/gui/target/gui-1.0-SNAPSHOT.jar" resulted in:

META-INF/
META-INF/MANIFEST.MF
META-INF/maven/
META-INF/maven/com.acme/
META-INF/maven/com.acme/gui/
META-INF/maven/com.acme/gui/pom.xml
com/
com/acme/
com/acme/gui/
com/acme/gui/Main.class
gui.properties
META-INF/maven/com.acme/gui/pom.properties

which looks fine. I also ran "m2 site:site" as a random goal and that seemed to work too, ie a target/site directory was created with all the files correctly generated underneath.

***************************

My conclusions are that it seems too easy so far and that I've missed a howler - if somebody could point it out?? Also in the acme/pom.xml file I would still need to add the equivalent test tags, eg <testResourceDirectory>.

Would it be possible to encapsulate these tweaks and any others that become apparent into a plugin so I could do something like the following in any application (root) pom:

<build>
  <plugins>
    <plugin>
      <groupId>com.maven.plugins</groupId>
      <artifactId>project-structure</artifactId>
      <version>1.0</version>
      <configuration>
        <method>one-tree</method>
      </configuration>
    </plugin>
  </plugins>
</build>

Thanks
AW

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to