Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Overview

In a corporate environment it makes sense to have some control over the setup of Maven.
For example:

  • restricting dependencies to approved versions of artifacts
  • reducing network bandwidth by having a maven repository proxy locally
  • sharing corporate assets by deploying them centrally

These scenarios can be realized by using a corporate Maven repository
and a Maven proxy. Be very careful not to confuse these two concepts as both
services are often located on the same physical machine and it is easy to get
them mixed up.

This guide will recommend installing both the Maven corporate repository and
the Maven proxy on a single machine and to make this guide a bit more readable
this machine will be called NUCLEUS.

To get an overview of repositories please read http://maven.apache.org/guides/introduction/introduction-to-repositories.html

For another example of repository setup with diagrams showing this configuration see http://cvs.peopleware.be/training/maven/maven2/repositories.html

Creating a corporate repository

Prerequisites

A web server already running and configured on NUCLEUS.

A web server is needed so that the corporate repositories can be accessed from the local desktops.

scp access to NUCLEUS

It is out of scope for this guide to walk through setting scp up on the server.
On a Unix machine a SSH server is needed.

The client will need a SSH client. SSH clients are available for Unix at http://www.openssh.com/ and Windows at http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Shell access to NUCLEUS

Shell access is needed to exectute commands and to configure the initial repository layout.
This may be done in conjunction with a sysadmin if you do not have the required priveleges.

Write access to a web server visible directory.

In this guide the Maven repositories will be installed into a location that has been configured for viewing on the web by your web server.

This guide will use the location WEB_ROOT/maven2.

Configuration

A corporate repository contains the following artifacts:

Artifacts available from other external repositories are not located in the
corporate repository. However these repositories may be proxied.

Separate repositories are created to physically seprate the logically
different artifacts from each other. You could also create one repository
and store all the artifacts within the one repository.

Create the repositories

In the WEB_ROOT/maven2 directory (which your sysadmin has already created)
create three new directories:

  • inhouse
  • external_free
  • external_non_free

If you are on a Unix machine ensure that the WEB_ROOT/maven2 directory has
g+ws permission (the s bit ensures that files and directories created will
have the same group access control).

Configure settings.xml

Now that the repositories have been created each deployer's settings.xml
file will need to specify these repositories in the server section:

Note: There appears to be some bugs with permissions not being set.
You may need to manually set the permissions after deployment.

    <server>
      <id>inhouse</id>
      <username>DEVELOPERS_USERNAME</username>
      <privateKey>PATH/TO/SSH.key</privateKey>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>

    <server>
      <id>external_free</id>
      <username>DEVELOPERS_USERNAME</username>
      <privateKey>PATH/TO/SSH.key</privateKey>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>

    <server>
      <id>external_non_free</id>
      <username>DEVELOPERS_USERNAME</username>
      <privateKey>PATH/TO/SSH.key</privateKey>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
    </server>
  • Deploy artifacts into repository
    • Deploying inhouse artifacts

Inhouse artifacts should have the correct sections of the pom completed
so that the deploy goal will work without having to specify any extra
arguments.

    ...
    <distributionManagement>
        <repository>
            <id>internal</id>
            <name>Internal Corporate Repository</name>
            <url>
                scp://NUCLEUS/PATH/TO/WEB_ROOT/maven2/internal</url>
        </repository>
    </distributionManagement>
    • Deploying external free or external non free artifacts

External free (ones not available from ibiblio because of annoying
license restrictions) and External non free artifacts can be deployed
to their respective repository.

Since these are normally well versioned jar files there is no need for any
snapshots in these repositories.

For further documentation on the deploy goal see
http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html.

For example the weblogic 8.1sp5 jar is an external non free jar and
therefore needs to be deployed into the external_non_free repository.
Assuming that the weblogic.jar is in the current directory then use the
following command:

mvn deploy:deploy-file -DgroupId=weblogic -DartifactId=weblogic -Dversion=8.1.5 \
  -DgeneratePom=true \
  -Dpackaging=jar \
  -Dfile=weblogic.jar \
  -DrepositoryId=external_non_free \
  -Durl=scp://NUCLEUS/PATH/TO/WEB_ROOT/maven2/external_non_free
  • Defining repositories in settings.xml

By defining these repositories in the settings.xml they will automatically
get checked for artifacts.

Note that these repositories do not contain plugins and if plugins are
needed then the pluginRepositories section will need to be completed with
appropriate details. Inhouse Corporate plugins are likely to be the only
ones needing a repository definition.

    ...
    <profiles>
        <profile>
            <id>repositoryDefinitions</id>
            <repositories>
                <repository>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                        <checksumPolicy>warn</checksumPolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                        <checksumPolicy>warn</checksumPolicy>
                    </snapshots>
                    <id>inhouse</id>
                    <name>Inhouse Corporate Repository</name>
                    <url>http://NUCLEUS/maven2/inhouse</url>
                    <layout>default</layout>
                </repository>
                <repository>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                        <checksumPolicy>warn</checksumPolicy>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>external_free</id>
                    <name>External Free Corporate Repository</name>
                    <url>http://NUCLEUS/maven2/external_free</url>
                    <layout>default</layout>
                </repository>
                <repository>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>daily</updatePolicy>
                        <checksumPolicy>warn</checksumPolicy>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>external_nonfree</id>
                    <name>External Non-Free Corporate Repository</name>
                    <url>http://NUCLEUS/maven2/external_non_free</url>
                    <layout>default</layout>
                </repository>
            </repositories>
        </profile>
        ...
    </profiles>
  ...
  <activeProfiles>
    <activeProfile>repositoryDefinitions</activeProfile>
  </activeProfiles>

Creating a Maven proxy (STILL TO BE COMPLETED)

A Maven proxy can be thought of as a Maven mirror that aggregates Maven
repositories.

This document will walk through the setup of maven-proxy
http://maven-proxy.codehaus.org/. At least one other alternative exists
called Proximity
https://is-micro.myip.hu/projects/ismicro-commons/proximity/projects-overview.html
however I found the documentation to be sparse or non existant as of
2006-01-13.

  • Prerequisites

You will need the following before you can start setting up maven-proxy.

  • Build maven-proxy

There is a "build.sh" file in the root of maven-proxy that will build the
sytem. If you are on a windows machine then you will need to manually run
the steps from the script.
In each directory core and standalone run:

maven clean build:snapshot

This guide will walk through the use of the standalone server which when
built will be in "standalone\target\maven-proxy-standalone-SNAPSHOT-app.jar"

  • Upload maven-proxy to NUCLEUS

If you are building maven-proxy on a local workstation then upload the
maven-proxy-standalone-SNAPSHOT-app.jar and maven-proxy.project to NUCLEUS.

  • No labels