Question

I am trying to configure the deploy step in a Maven 3.0.4 POM using the <distributionManagement> tag. From XSD for POMs (line 1389), it suggests that merely providing the id should allow Maven too look up the corresponding values from the settings.xml file. I have the desired server listed (which is configured correctly since I can pull dependencies from it and see it mentioned when running in -X debug mode: [DEBUG] Repositories (dependencies): [archiva.snapshots (http://snap-mvnrepo.initech.com/archiva/repository/snapshots, releases+snapshots)]) in the settings.xml. However, when I just provide the <id> in my POM and try to deploy, I get an error that Maven is missing the URL for the repository, but when I explicitly provide the <url> the deploy works.

Does anyone know what I should do to get it working by id only? I don't want to hard code the URL.


DISCLAIMERS: Typos are likely the result of anonymization, but it is possible that they are "real" so feel free to point away at any.

About the <id> child tag of <repository> from the XSD for POMs (line 1389):

A unique identifier for a repository. This is used to match the repository to configuration in the settings.xml file, for example.

From my settings.xml:

<profile>
    <id>archiva_dev</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <repositories>
        <repository>
            <id>archiva.snapshots</id>
            <name>Initech Internal Snapshot Repository</name>
            <url>http://snap-mvnrepo.initech.com/archiva/repository/snapshots</url>
        </repository>
    </repositories>
</profile>

From my (failing) pom.xml:

<distributionManagement>
    <repository>
        <id>archiva.snapshots</id>
    <!--
        <name>Initech Internal Snapshot Repository</name>
        <url>http://snap-mvnrepo.initech.com/archiva/repository/snapshots</url>
    -->         
    </repository>
</distributionManagement>

The error:

Caused by: java.lang.IllegalStateException: Failed to create release distribution repository for com.initech.ws:initechws:pom:1.0-SNAPSHOT
        at org.apache.maven.project.MavenProject.getReleaseArtifactRepository(MavenProject.java:1853)
        at org.apache.maven.project.MavenProject.getDistributionManagementArtifactRepository(MavenProject.java:1377)
        at org.apache.maven.plugin.deploy.DeployMojo.getDeploymentRepository(DeployMojo.java:227)
        at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:118)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        ... 20 more
Caused by: org.apache.maven.artifact.InvalidRepositoryException: URL missing for repository archiva.snapshots
        at org.apache.maven.repository.legacy.LegacyRepositorySystem.buildArtifactRepository(LegacyRepositorySystem.java:775)
        at org.apache.maven.project.MavenProject.getReleaseArtifactRepository(MavenProject.java:1843)
        ... 24 more
Was it helpful?

Solution

The /project/distributionManagement/id value defines the /settings/servers/server/id to match against in order to identify the credentials to use when connecting to the url specified by /project/distributionManagement/url

Because the URL for deployment is very often different from the URL for read access, and the same credentials may apply to multiple URLs, there is no looking up of /project/repositories/repository or /project/pluginRepositories/pluginRepository.

The short answer is thus that you must specify /project/distributionManagement/url in order to be able to deploy, and if you need credentials in order to deploy to that URL you need to specify /project/distributionManagement/id and ensure that the matching credentials exist in your settings.xml

How could we update the documentation to make the above clearer and prevent future users from becoming confused in the manner you have been?

Update

The modello toolchain is generating the XSL with only some of the sentences, so

A unique identifier for a repository. This is used to match the repository to configuration in the settings.xml file, for example.

Is actually

A unique identifier for a repository. This is used to match the repository to configuration in the settings.xml file, for example. Furthermore, the identifier is used during POM inheritance and profile injection to detect repositories that should be merged.

Source

Finally in order to fully make sense of the sentence, you need to be aware that the settings.xml file is just the source of settings when Maven is invoked from the command line. Maven Embedder may actually mean that the settings provided to Maven come from some other source entirely (think, e.g. from the configuration database of Eclipse or another IDE) which is the reason for some of the fun in MRELEASE-577.

A better way to read the first sentence might be

A unique identifier for a repository. This is used to match the repository to configuration, for example in the settings.xml file.

But if you can suggest something even better I will update the docs accordingly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top