0

Need to deploy a artifacts from two remote repositories based on environment specific. So I tried by using profiles in distribution management in pom.xml

   <profiles>
<profile>
    <id>dev-repository</id>
    <activation>
        <property>
            <name>devRepo</name>
            <value>true</value>
        </property>
    </activation>
    <properties>
    </properties>
    <distributionManagement>
        <repository>
        <id>dev</id>
        <url>https://nexus/dev</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    </distributionManagement>
</profile>

<profile>
    <id>qa-repository</id>
    <activation>
        <property>
            <name>!devRepo</name>
        </property>
    </activation>
    <properties>
    </properties>
    <distributionManagement>
          <repository>
        <id>qa</id>
        <url>https://nexus/qa</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    </distributionManagement>
</profile> 
</profiles>

Tried Activating the profiles

> mvn clean deploy -PdevRepo

I am getting the following error.

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

seems like pom can't recognize the distributionMangement tags.

But It's working fine without profiles for single distributionManagement.

Any one please advise on this ?

Reference

Setting up Maven to allow deployment to different repositories easily

Deployment issue with Maven Plugin

Debugger
  • 690
  • 1
  • 18
  • 41

1 Answers1

0

Instead of using profiles, I would define a distributionManagement with a url of the form <url>https://nexus/${target.repo}</url>

Then you can do something like mvn clean deploy -Ptarget.repo=dev.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Note that this answer might be subject to https://issues.apache.org/jira/browse/MNG-6870. – Michael-O Mar 12 '20 at 12:07
  • @Michael-O Thank you for the hint (I did not know that), but AFAIK this does not influence the distributionManagement. I have a distributionManagement property in the settings.xml, and commandline should work the same. – J Fabian Meier Mar 12 '20 at 12:20