Skip to content
Advertisement

Nexus & Maven Corporate Pom – What should it contain?

We are currently evaluating to establish an internal company nexus repository for our java development.

Unfortunately there are still some questions unanswered, but maybe you can help.

A parent pom for all projects inside the company seems to be best practice. What is not clear is what this pom should contain, besides the <organization>section.

Is it best practice to also specify the <distributionManagement> inside this pom? If yes, what should it contain and what should it look like if we want to reference the company nexus (<site>, <repository>, <snapshotRepository>) ?

How to handle the fact that (according to sonatype) it is best practice that each project has its own repository without the need to specify the nexus root path in each pom?

Should we specify also the <repositories> and <pluginRepositories> section there (referencing our internal nexus)?

Additionally we want that basically each project can deploy it’s own site, could we specify this also inside the parent pom? And if yes, what should the site plugin configuration look like?

The best would be if someone could provide a full, examplary corporate pom that can be used with an internal nexus repository.

Or is it even better to put this stuff inside the settings.xml to not bind the project to a certain repository? But as far as I know the <distributionManagement> can’t be specified inside the settings.xml? Also this will be a tedious work to update if the nexus url changes someday?

I am really confused about this whole stuff, eventhough I tried to read a lot about it.

Thank you in advance!


UPDATE/Solution

Thanks to Michael-O‘s answer below I have the information I need.

  1. <repositories> and <pluginRepositories> tag belong to the settings.xml. This is the place to specify the nexus repository for “Downloading” (optionally include credentials using <servers>
  2. <distributionManagement> belongs to the corporate base pom, referencing a basic Nexus repository for releases and snapshots. This is the place to specify the nexus repository for “Uploading” (deploying).
  3. If sub-repositories (for logically grouping projects) are needed, they are specified inside the projects pom.xml and therefore override the ones inside the company pom. To simplify this and for keeping the basic nexus url only inside the corporate pom (beware of url changes) it might be useful/possible to specify the repositories inside <distributionManagement> in the following manner:

    <repository>
      <id>company-repository</id>
      <name>Internal Releases</name>
      <url>http://my.nexus.repo/releases/${subRepositoryId}-releases</url>
    </repository>
    
  4. An exemplary corporate pom can be found in this post

  5. To prevent configuration changes inside the pom files or settings one could use an alias for the nexus url. Though this would mean additional effort from the administrative side.
  6. If a site for a project is needed no general definition inside the corporate pom can be used, it has to be declared individually for each project pom. To simplify this process the site nexus url could be stored inside a property of the corporate pom that can then be referenced inside the site distribution management of the project poms.

The corporate pom could contain something similar to this:

  <project>
    ....
    <properties>
      <repository.group>common</repository.group>
      <repository.url.base>http://my.nexus:port/nexus/content</repository.url.base>
      <repository.url.repositories>${repository.url.base}/repositories</repository.url.repositories>
      <repository.url.sites>${repository.url.base}/sites</repository.url.sites>
    </properties>

    <distributionManagement>
      <repository>
        <id>company-repository</id>
        <name>Internal Releases</name>
        <url>${repository.url.repositories}/${repository.group}-releases</url>
      </repository>
      <snapshotRepository>
        <id>company-repository</id>
        <name>Internal Snapshots</name>
        <url>${repository.url.repositories}/${repository.group}-snapshots</url>
      </snapshotRepository>
    </distributionManagement>
    ....
  </project>

The project pom similiar to this:

  <project>
    ...
    <properties>
      <repository.group>project-group</repository.group>
    </properties>

    <distributionManagement>
      <site>
        <id>company-repository</id>
        <name>Internal Releases</name>
        <url>dav:${repository.url.sites}/project-site</url>
      </site>
    </distributionManagement>
    ...
  </project>

WARNING: One might wonder why to not directly include the site part into the corporate pom. This is not possible, as you can’t deploy multiple sites to the same site repository without creating a mess. Using the way above one does not need to create a repository for each project, but is able to group them logically together into larger groups or leave them in the common-releases/snapshots group/repository.

Advertisement

Answer

You can have a look at the Apache Parent POM or the Maven Parent POM. A minimal corporate POM should 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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>example-parent</artifactId>
  <version>1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>Exmaple Parent POM</name>
  <organization>
    <name>Example Inc.</name>
  </organization>

  <!-- This marked as deprecated for Maven 3.x. This is checked by maven-enforcer-plugin -->
  <!-- http://jira.codehaus.org/browse/MNG-5297 -->
  <prerequisites>
    <maven>${maven.version}</maven>
  </prerequisites>

  <scm>
    <connection>scm:svn:https://example.com/repos/svn/ExmapleJava/example-parent/trunk/</connection>
    <developerConnection>scm:svn:https://example.com/repos/svn/ExmapleJava/example-parent/trunk/</developerConnection>
    <url>https://example.com/repos/websvn/browse/ExmapleJava/example-parent/trunk/</url>
  </scm>

  <distributionManagement>
    <repository>
      <id>nexus-example</id>
      <name>Nexus Exmaple Release Repository</name>
      <url>https://example.com/nexus/content/repositories/example-releases</url>
    </repository>
    <snapshotRepository>
      <id>nexus-example</id>
      <name>Nexus Exmaple Snapshot Repository</name>
      <url>https://example.com/nexus/content/repositories/example-snapshots</url>
    </snapshotRepository>
  </distributionManagement>

  <properties>
    <maven.version>3.2</maven.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <surefire.version>2.19</surefire.version>
    <javadoc.version>2.10.3</javadoc.version>
  </properties>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.3</version>
        </plugin>
        <plugin>
          <artifactId>maven-source-plugin</artifactId>
          <version>2.4</version>
          <configuration>
            <excludeResources>true</excludeResources>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.6</version>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.6</version>
        </plugin>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.3</version>
          <configuration>
            <mavenExecutorId>forked-path</mavenExecutorId>
            <autoVersionSubmodules>true</autoVersionSubmodules>
            <useReleaseProfile>false</useReleaseProfile>
            <tagNameFormat>@{project.version}</tagNameFormat>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-help-plugin</artifactId>
          <version>2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>
          <version>${javadoc.version}</version>
          <configuration>
            <quiet>true</quiet>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>2.7</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>${surefire.version}</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>2.6</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.10</version>
        </plugin>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>2.6.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.4</version>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>buildnumber-maven-plugin</artifactId>
          <version>1.4</version>
          <configuration>
            <buildNumberPropertyName>buildRevision</buildNumberPropertyName>
            <timestampPropertyName>buildTimestamp</timestampPropertyName>
            <scmBranchPropertyName>buildScmBranch</scmBranchPropertyName>
            <revisionOnScmFailure>non-SCM</revisionOnScmFailure>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>versions-maven-plugin</artifactId>
          <version>2.2</version>
          <configuration>
            <generateBackupPoms>false</generateBackupPoms>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>appassembler-maven-plugin</artifactId>
          <version>1.10</version>
          <configuration>
            <includeConfigurationDirectoryInClasspath>false</includeConfigurationDirectoryInClasspath>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <version>1.9.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>1.4.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.8</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce-maven</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireMavenVersion>
                  <version>${maven.version}</version>
                  <message>This project requires at least Maven ${maven.version}</message>
                </requireMavenVersion>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>example-release</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-sources</id>
                <goals>
                  <goal>jar-no-fork</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

The plugins of course should vary for your company but this gets you started. This is actually our parent just removed our local information.

There is no information for the site deployment because we don’t use it. Set it if you use it.

At no time your POM should contain <repositories> and <pluginRepositories> because this is bad practice. Ideally, your work with a repo group in Nexus mirroring (in settings.xml) all of your requests.

Inherit from and be happy.

How to handle sites: Generally, each project has its own site and should be overridden in the dist mngt section. This is different to the artifacts. Whether your will host on Nexus or on a webserver like Apache is up to you. The bottom line is that every project site needs its distinct URL.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement