Multi Module ************ Links ===== - `How do I build more than one project at once?`_ - `Maven 2 Notes, Part 6: Multiproject Builds`_ - `Explain multi-module support in M2`_ - `Eclipse and Maven Multiple Module Projects`_ Sample ====== sample-multi-module_ Imagine a sample project with this folder structure: :: ./pom.xml ./module-a/pom.xml ./module-b/pom.xml Parent ------ The parent ``pom.xml`` file will look like this: :: 4.0.0 com.sample 1.0-SNAPSHOT parent-app pom Parent App module-a module-b Module ------ The module ``pom.xml`` files, ``module-a`` and ``module-b`` are virtually the same. They will only differ with the ``artifactId``, ``packaging`` and ``name`` :: com.mycompany parent-app 1.0-SNAPSHOT 4.0.0 com.mycompany module-a ... **Note:** - It is important to identify the ``parent`` from each of the modules. - If you use ``mvn eclipse:eclipse`` it looks like you need to import each module into Eclipse separately. - If you don't specify the ``version`` in the module, it appears to inherit the version of the parent (which is probably what you want). **Note**: If your module does specify a version, the project files generated by the Eclipse plugin might refer to ``jar`` files in the Maven repository rather than the project. - If you use ``archetype:create`` it will set-up the ``pom.xml`` files correctly. - For the release plugin, :doc:`mvn-plugin-release`, the ``scm``, ``connection`` only needs to be specified in the parent pom. Dependencies ------------ The parent ``pom.xml`` file can use the ``dependencyManagement`` tag to specify versions of dependencies which can be used in the modules: :: commons-dbcp commons-dbcp 1.2.1 commons-dbutils commons-dbutils 1.0 The ``dependencies`` tag in the module ``pom.xml`` file will inherit the version of the artifact from the parent: :: commons-dbcp commons-dbcp test commons-dbutils commons-dbutils Note: The ``scope`` can be changed in the module. To add a dependency to one of the other modules in the project: :: com.sample module-b ${project.version} - This is the configuration to use if you want to release all modules with the same version number. Releasing all modules with the same version number will make it much simple to identify the version number of deployed jar files. In any case, the release plugin increments the version number for every module in the project even if no changes have been committed. - If you do want a different version number for a module the release plugin, :doc:`mvn-plugin-release`, will automatically update the version number in the module and the ``dependencyManagement`` section of the parent pom e.g. :: 5.3-SNAPSHOT - Also see `Maven best practices: Use dependency management for multi module projects`_. Effective pom ============= To view the effective pom.xml file for a project: :: mvn help:effective-pom POM Dependency ============== ...declare a pom as a dependency, so that its dependencies would be inherited... `POM Inheritance`_ :: JDBC POM: ... my-jdbc-project pom ... add jdbc dependencies here, like mysql jdbc, or sqlserver jdbc ... Then, in your project that needs to use the jdbc drivers: ... my-jdbc-project ... pom .... Site ==== - :doc:`mvn-plugin-site-multi-module` .. _`How do I build more than one project at once?`: http://maven.apache.org/guides/getting-started/index.html#How%20do%20I%20build%20more%20than%20one%20project%20at%20once? .. _`Maven 2 Notes, Part 6: Multiproject Builds`: http://communitygrids.blogspot.com/2006/02/maven-2-notes-part-6-multiproject_06.html .. _`Explain multi-module support in M2`: http://www.mail-archive.com/users@maven.apache.org/msg41444.html .. _`Eclipse and Maven Multiple Module Projects`: http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html .. _sample-multi-module: http://toybox/hg/sample/file/tip/java/maven/sample-multi-module .. _`Maven best practices: Use dependency management for multi module projects`: http://www.bhaskarvk.info/content/maven/dependency_management.html .. _`POM Inheritance`: http://www.nabble.com/POM-Inheritance-tf3304518s177.html#a9234650