41

I have maven projects and I want to deploy my artifacts on internal nexus repository which is configured to have my snapshots and releases on two separate places. So I can not use 'distributionManagement' as this would hardcode the location. So I have defined couple of in my settings.xml say 'releaseRepository' and 'snapshotRepository' and each have parameter 'release' which should be set to 'true' for releases and 'false' for snapshots.

I am running my build with following command to release my artifacts;

mvn clean deploy -DaltDeploymentRepository=releaseRepository::<DON'T KNOW WHAT GOES HERE SO LEFT IT EMPTY>::htp://abc.com/repositores/my-releases/ -Drelease=true

Now when I am running above command it fails because value for 'layout' is not provided and I get exception and build fails.

I couldn't find any information on what should be the value for 'layout', I have around 10 projects which I want to build and release after one another.

Simon Gibbs
  • 4,737
  • 6
  • 50
  • 80
SJunejo
  • 1,316
  • 4
  • 23
  • 39
  • the following could be interesting : https://stackoverflow.com/questions/41611671/difference-between-altdeploymentrepository-and-altreleasedeploymentrepository – yunandtidus Jul 19 '18 at 08:22

5 Answers5

62

altDeploymentRepository String - Specifies an alternative repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ). Format: id::layout::url

— (source)

So, in you case: releaseRepository::default::http://your.repo.url (see here for layout).

  • Thanks for...just got it...my build gone bit more far but now failed with 'permission denied'. I have tab in the same settings.xml with username and password but I am not sure if its in use, I mean I can not see any link between my profile and server definition, how can I link them i.e. how can I say maven to use server id=abc to authenticate and then use its config to upload? – SJunejo Nov 25 '12 at 01:37
  • Thats whet `id` stand for in `altDeploymentRepository` –  Nov 25 '12 at 01:41
  • id=PROFILE_NAME? is it or should I use the server name there? – SJunejo Nov 25 '12 at 01:45
  • You could also provide and username and password for the alternative repository embedded in the url on the command line, e.g. `mvn clean deploy -DaltDeploymentRepository=releaseRspository::default::http://username:password@your.repo.url` – alphaloop Apr 13 '17 at 01:08
2

"layout" is a legacy switch provided for backwards compatibility with Maven 1, and at this point an anachronism. If you are using Maven 2 or Maven 3 (as I believe at least 99.99% of the world must be at this point) it is indeed "default", as described elsewhere here. By stating that the answer is unequivocally "default", the question of the utility of the switch is obviated; if it is always "default", which does it still exist?

If you are actually using Maven 1 still, it should be "legacy", but I hope no one is. All this is describe in the Maven specifications:

layout Either default for the Maven2 layout or legacy for the Maven1 layout. Maven3 also uses the default layout.

https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

Alex Kogon
  • 46
  • 2
2

This may not be answer to your specific question, but just because you have different repository for release and snapshot, you need not use alt location property. It can be still managed by distribution management tag in pom.xml

Here is the sample snippet which has both release and snapshot repository

  <distributionManagement>
    <repository>
      <id>releaseRepository</id>
      <name>releaseRepository</name>
      <url>release-url-goes-here</url>
    </repository>
    <snapshotRepository>
      <id>snapshotRepository</id>
      <name>snapshotRepository</name>
      <url>snapshot-url-goes-here</url>
    </snapshotRepository>
  </distributionManagement>
Hemang
  • 1,351
  • 1
  • 10
  • 20
  • Maven picks the correct repository based on the version specified. If the version is a snapshot version then the snapshot repository information is used. So for example, if maven sees `1.2.3-SNAPSHOT` as the version then it uses the **. – PatS Feb 27 '23 at 20:55
0

In maven3, if using deploy plug-in version 3.0.0 you can configure the following in settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <servers>
        <server>
            <id>nexus-snapshots</id>
            ...
        </server>
        <server>
            <id>nexus-releases</id>
            ...
        </server>
    </servers>
    ...
    <profiles>
        <profile>
            <id>myprofile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <altSnapshotDeploymentRepository>nexus-snapshots::https://someurl.com/nexus/repository/maven-snapshots/</altSnapshotDeploymentRepository>
                <altReleaseDeploymentRepository>nexus-releases::https://someurl.com/nexus/repository/maven-releases/</altReleaseDeploymentRepository>
            </properties>
            ...
        </profile>
    </profiles>
</settings>

If deploy plug-in is before version 3.0.0, then the following is the respective settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <servers>
        <server>
            <id>nexus-snapshots</id>
            ...
        </server>
        <server>
            <id>nexus-releases</id>
            ...
        </server>
    </servers>
    ...
    <profiles>
        <profile>
            <id>myprofile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <altSnapshotDeploymentRepository>nexus-snapshots::default::https://someurl.com/nexus/repository/maven-snapshots/</altSnapshotDeploymentRepository>
                <altReleaseDeploymentRepository>nexus-releases::default::https://someurl.com/nexus/repository/maven-releases/</altReleaseDeploymentRepository>
                <altDeploymentRepository>nexus-releases::default::https://someurl.com/nexus/repository/maven-</altDeploymentRepository>
            </properties>
            ...
        </profile>
    </profiles>
</settings>

This way all projects will have defined the distribution management settings (in addition to the ones specified in the projects pom.xml's). No need to explicitly specify them in command line.

You can change the deploy plug-in version on project pom.xml by specifying it:

   <plugins>
      ...
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>3.0.0</version>
      </plugin>
      ...
    </plugins>

Reference: https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

pringi
  • 3,987
  • 5
  • 35
  • 45
0

The maven deploy plugin currently org.apache.maven.plugins:maven-deploy-plugin:3.1.0 is used to copy/deploy maven artifacts to a Maven Repo (like Maven Central or NEXUS). See https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html.

This plugin needs to know where you want your maven artifacts deployed and how to login to that website.

The plugin gets the login and URL from your POM or from a command line option.

From your POM file

When using your pom, Distribution Management defines where to deploy to.

In this approach, a pom.xml file (or parent.pom) defines the URL of the maven repository to use.

An example of this is shown below:

<distributionManagement>
    <repository>
      <id>corp1</id>
      <name>Corporate Repository</name>
      <url>https://corp1.example.com/repository/public</url>
      <layout>default</layout>
    </repository>
    <snapshotRepository>
      <id>corp1-snapshot</id>
      <name>Corporate Snapshot Repo</name>
      <url>https://corp1.example.com/repository/snapshot</url>
    </snapshotRepository>

Command line option -DaltDeploymentRepository

See https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

In this approach, the command line specifies the login and URL of a maven repository to use.

The syntax for the -DaltDeploymentRepository has for many years been the same. The syntax was: -DaltDeploymentRepository=id::layout::URL.

  • id - referred to a server's <id> value in a maven settings file (typically at $HOME/.m2/settings.xml).

  • layout - is nearly always default, and it refers to the format of the maven repository. Maven 1.x used one format and maven 2.x and higher used a different format. See also What does repository layout mean.

  • URL - refers to a maven repository to which the maven deploy plugin can write to.

How does maven decide when to use POM vs the command line option

Maven will automatically use the <snapshotRepository> if the version in the pom.xml file ends with -SNAPSHOT. For example, <version>12.5.59-SNAPSHOT</version>. Otherwise, the <repository> information will be used.

A more detailed/complete description is here, Difference between altDeploymentRepository and altReleaseDeploymentRepository

Example

A user runs the following command:

mvn deploy -DaltDeploymentRepository=server.id::default::https://example.com/repository/public

For the above command, server.id means the id of the server as defined in the $HOME/.m2/settings.xml settings file. For example,

<servers>
  <server>
    <id>server.id</id>
    <username>exampleuser</username>
    <password>examplepass</password>
  </server>
</servers>

The newer versions of the maven-deploy-plugin (versions 3.0 and higher) switched to a different syntax for the -DaltDeploymentRepository option and that syntax simply drops the ::default from the string. So the new syntax is:

-DaltDeploymentRepository=server.id::URL

So the login information and the URL are still provided, only the ::default portion of the value was removed.

Things to be aware of

If you pass in the newer syntax server.id::URL, but the maven application is still using the older maven deploy plugin (e.g., maven-deploy-plugin < 3.0), then you will get an error like:

. . . Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

This happens because the old maven plugin is looking for the older syntax. To fix this add ::default to the command line option.

Switching to the version 3.x of the maven-release-plugin

To use the newer version you'll need something like this in your pom file.

<build>
  <plugins>
    <plugin>
      <artifactId>maven-deploy-plugin</artifiactId>
      <version>3.1.0</version>
    </plugin>
  </plugins>
</build>
PatS
  • 8,833
  • 12
  • 57
  • 100