Title: Configure Maven settings for deployment
Tags: maven;jenkins;nexus
Question: I want to deploy artifacts to Nexus from Jenkins to different repositories (like ```builds-all```, ```builds-verified```, ```releases```). The thing is that I want to keep minimal configuration in the project POM file. My settings file now looks like:

```<servers&gt;
    <server&gt;
        <id&gt;orion-nexus</id&gt;
        <username&gt;admin</username&gt;
        <password&gt;password</password&gt;
    </server&gt;
</servers&gt;

<localRepository&gt;~/.m2/repository</localRepository&gt;

<profiles&gt;
    <!-- Deployment configuration for CI builds for mainline --&gt;
    <profile&gt;
        <id&gt;build</id&gt;
        <repositories&gt;
            <repository&gt;
                <id&gt;builds-all</id&gt;
                <url&gt;http://orion-nexus:8081/</url&gt;
                <snapshots&gt;
                    <checksumPolicy&gt;fail</checksumPolicy&gt;
                </snapshots&gt;
            </repository&gt;
        </repositories&gt;
    </profile&gt;
</profiles&gt;
```



Project POM:

```<distributionManagement&gt;
    <repository&gt;
        <id&gt;orion-nexus</id&gt;
        <layout&gt;default</layout&gt;
        <url&gt;<!-- how to avoid explicit URL? --&gt;</url&gt;
    </repository&gt;
</distributionManagement&gt;
```

I wan to run deploy like ```mvn -B -P build clean install deploy```. However, I don't understand how to avoid setting explicit URL in distribution management section. Can I set a variable in settings file and propagate it to my POM? 

Is there any step-by-step guide for such workflow?

Comment: Why do you not want a URL here? It's the perfect place for it: each project declares where it should be pushed. There was a long mail about this on the [Maven mailing list](http://maven.40175.n5.nabble.com/Can-t-specify-distributionManagement-in-settings-xml-td3181781.html) that will interest you. At the end of it, you'll agree :)

Comment: If you need it for more than one project simply start creating a corporate pom which defines this.

Here is the accepted answer: You can declare a property inside a profile on your ```settings.xml``` and use its name within ```<distributionManagement/&gt;``` configuration.

settings.xml

```<profiles&gt;
    <profile&gt;
        <id&gt;distmgt</id&gt;
        <properties&gt;
            <distUrl&gt;scp://...</distUrl&gt;
        <properties/&gt;
    </profile&gt;
</profiles&gt;
```

pom.xml

```<distributionManagement&gt;
    <repository&gt;
        <id&gt;orion-nexus</id&gt;
        <layout&gt;default</layout&gt;
        <url&gt;${distUrl}</url&gt;
    </repository&gt;
</distributionManagement&gt;
```

And finally

```mvn -P distmgt clean deploy
```

You can avoid the ```-P build``` params using activation.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:02/03/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<maven><jenkins><nexus>', 'Title': 'Configure Maven settings for deployment', 'ViewCount': 2457, 'id': 35184996, 'user_AboutMe': '<p>Senior DevOps Engineer</p>\n\n<p>CI/CD, Cloud, Deployment automation basically in Java-based world</p>\n', 'user_AccountId': 2382826.0, 'user_DisplayName': 'vladfau', 'user_Reputation': 1003.0, 'user_Views': 105.0, 'user_id': 2084479.0}}