Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Super POM

I'm new to Maven and working on creating a build for my company. We don't want to connect out to the Maven Central Repository, and we have a different directory structure for src and test code than specified in the super pom. I figured the best way to handle this is to create a customer super pom, but I'm wondering - where do I actually put the super pom so my project poms can reference it? Does it go in the repository somewhere? If so, where?

Thanks, Jeff

like image 325
Jeff Storey Avatar asked Jun 12 '09 13:06

Jeff Storey


2 Answers

My suggestion is that you create a parent POM from which your projects can derive your settings. This parent POM is simply another Maven 2 project, but with the type "pom" instead of "jar".

For example, you could have a parent pom like this:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.projectname</groupId>
    <artifactId>projectname</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <name>projectname</name>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <superprop1>this property is available in all child projects</superprop1>
        <superprop2>this property is available in all child projects</superprop2>
        <superprop3>this property is available in all child projects</superprop3>
    </properties>
</project>

And a child of the project could look like this:

<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">
    <parent>
        <artifactId>projectname</artifactId>
        <groupId>com.company.projectname</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>        
    <artifactId>child-project</artifactId>
    <packaging>jar</packaging>
    <name>child-project</name>
    <description>
        My child project
    </description>
</project>

Everything you declare in the parent POM is now available in the child pom. In the example about, the child project will automatically have the JUnit dependency available. Doing it in this way will also ensure that the environment is automatically figured compared to if each developer would have to mess around with the super POM of their Maven installation.

like image 140
Allan Lykke Christensen Avatar answered Oct 04 '22 02:10

Allan Lykke Christensen


You are probably correct, a super-pom is the way to go in this situation. As for where you put it, you will need to create a local maven repository and give developers access to it. Here are some useful (and free) programs:

  • Artifactory (http://www.jfrog.com/products.php)
  • Nexus (http://nexus.sonatype.org/)
  • Archiva (http://archiva.apache.org/)

Once you get a repository up an running, you will need to have each developer modify their settings.xml to reference the new repository server you have setup. The super pom you create will be deployed in the repository, so once they are configured to use it, then maven will pull the super pom down automatically.

Here is an example of an artifactory generated settings.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>all</name>
          <url>https://server.mycompany.com/artifactory/all</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>all</name>
          <url>https://server.mycompany.com/artifactory/all</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>all</name>
          <url>https://server.mycompany.com/artifactory/all</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>all</name>
          <url>https://server.mycompany.com/artifactory/all</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>
like image 31
Brad Lee Avatar answered Oct 04 '22 02:10

Brad Lee