tags:

views:

275

answers:

4

What is the best way to split up a large enterprise project in Maven?

It's easy enough to understand how to partition things vertically like this...

  1. You have a DAO project
  2. The DAO project is a dependency of the Service project
  3. The Service project is a dependency of the web project.

Does anybody have input on best practices in partitioning/splitting up really large projects in Maven.m

+3  A: 

Here's a few pointers:

  • Declare dependency versions in a common parent or use declare the versions in a specific project's dependencyManagement and reference it with import scope.
  • Avoid unversioned plugins. Declare plugin versions in a pluginManagement section.
  • Declare common plugin configurations in a parent pom, particularly reporting configurations.
  • Don't declare repositories in your POMs.
  • Use a repository manager like Nexus
  • Use properties to allow child projects to inherit configuration, but override key values (e.g. in the url for distributionManagement)
  • Set up a continuous integration server. Projects in development should have SNAPSHOT versions and be deployed to the repository regularly.
Rich Seller
good tips, but they don't really address is question...I think he's asking about how to restructure a large code base
Ken Liu
@Ken if that is the case, it is not a maven-2 question. The OP has already described how they intend to separate components. If they need further advice in that area it should be tagged accordingly (e.g. java refactoring).
Rich Seller
+6  A: 

Some things that have helped me

  • Use multi-module projects for projects that are related and only projects that are related. An EJB that exists only in a single EAR is a candidate for this. A bo layer that is used by an EJB and a client app is not.
  • One Artifact per pom, one deployable per multi-module project Do Not Waste Time trying to get around this.
  • Create dependency poms that include common sets of dependencies. That way you can include your DAO, your jdbc driver and your ORM tools with a single dependency. It also makes upgrading dozens of projects to the newest version of your ORM or DAO that much easier.
  • Create builder projects that exist only to run assembly and create deployment sets. This will keep multiple parts of your project in sync. Assembling large complex enterprise apps is often complicated enough that you need a mix of maven, shell scripts and/or ant:run tasks plus dozens of profiles. Putting the mess in a project far away from your code will contain the mess before it spreads.
  • Create tester projects for continuous integration use. Define your web and app servers in those poms as well as the test deployment info. Use of parent projects and common properties files will make testing deployment changes easier.
  • Define distributionManagement in a parent pom only if it is possible to make all sub-projects a child (or grand-child) of it.
  • Try not to depend on large files (EAR, WAR) being stuffed into your repository on every build. Removing the need for a 175mb WAR to be pushed to nexus on each snapshot improved our build times.
  • Try to define things as few times as possible. A DRY build is a happy build. Having 30 poms with source-version 1.5 or 30 poms using junit 3.8.2 is going to make upgrading to java 6 or junit 4.4 that much harder.

Hope this helps.

sal
A: 

It's all adjustment. Maven don't have all nor latest. mine here saved me you may look and just feel what's right for you.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.appspot.classifiedsmarket</groupId>
  <artifactId>classifiedsmarket</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>classifiedsmarket Maven Webapp</name>
  <url>http://maven.apache.org&lt;/url&gt;
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
            <scope>compile</scope>
        </dependency>
    <dependency>
            <groupId>httpunit</groupId>
            <artifactId>httpunit</artifactId>
            <version>1.6.1</version>
            <scope>compile</scope>
        </dependency>
    <dependency>
            <groupId>struts</groupId>
            <artifactId>struts</artifactId>
            <version>1.2.9</version>
            <scope>compile</scope>
        </dependency>
    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
            <scope>compile</scope>
        </dependency>
    <dependency>
            <groupId>informa</groupId>
            <artifactId>informa</artifactId>
            <version>0.6.0</version>
            <scope>compile</scope>
        </dependency>
    <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.3</version>
            <scope>compile</scope>
        </dependency>
    <dependency>
            <groupId>htmlunit</groupId>
            <artifactId>htmlunit</artifactId>
            <version>1.9</version>
            <scope>compile</scope>
        </dependency>

    <dependency>
 <groupId>javax.activation</groupId>
 <artifactId>activation</artifactId>
 <version>1.1</version>
</dependency>
<dependency>
 <groupId>javax.mail</groupId>
 <artifactId>mail</artifactId>
 <version>1.4</version>
</dependency>
<dependency>
            <groupId>dwr</groupId>
            <artifactId>dwr</artifactId>
            <version>1.1.3</version>
            <scope>compile</scope>
        </dependency>
<dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
            <scope>compile</scope>
        </dependency>
<dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.4</version>
            <scope>compile</scope>
        </dependency>
<dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>
<dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>









  </dependencies>
  <build>
    <finalName>classifiedsmarket</finalName>
    <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>RELEASE</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>RELEASE</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>RELEASE</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
  </build>
  <properties>
        <netbeans.hint.deploy.server>Tomcat55</netbeans.hint.deploy.server>
    </properties>
</project>
LarsOn
+5  A: 
Tim