blob: 9e142bfc683706b57a74c3e0d0a7a70b922b8c6d [file] [log] [blame]
I posted these instructions a little while ago on how to use Maven 2
with a non
standard single source tree rather than individual modules. Might be
useful for existing
projects without the budget or inclination to move over to the
standard structure.
Or maybe this technique would encourage a project to get an early
idea of how
maven would work with their code before actually migrating to the
standard layout,
with ilttle risk.
AW
-------------------------------------
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
> mvn 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 "mvn 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