mvn deploy:file to different repositories for snapshot and release version

社会主义新天地 提交于 2019-12-21 06:56:26

问题


Is it possible to in some way tell the maven deploy:file goal to deploy to two independent artifactories based on whether the version of the project is a snapshot / release?

I'm hoping there might be a property which indicates the fact the version has -SNAPSHOT prepended, or perhaps the default artifactory to deploy to (which has been worked out based on the version number already).

I thought about using two different profiles and working out if its a snapshot in ant by parsing the pom.xml file, but I'd rather a cleaner solution if possible.

Currently, my deploy plugin looks as follows, but this just deploys to the release artifactory regardless of the version;

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-deploy-plugin</artifactId>
   <version>2.5</version>
   <executions>
      <execution>
        <id>deploy-zip-created-by-ant-to-artifactory</id>
    <phase>deploy</phase>
    <goals>
       <goal>deploy-file</goal>
    </goals>
    <configuration>
       <repositoryId>${project.distributionManagement.repository.id}</repositoryId>
       <url>${project.distributionManagement.repository.url}</url>
       <file>${project.basedir}/Build/deploy/MyArtifact.zip</file>
       <pomFile>${project.basedir}/MyArtifact-pom.xml</pomFile>
    </configuration>
      </execution>
   </executions>
</plugin>

Many Thanks


回答1:


If you defined your repositories within your settings.xml you can use the

mvn deploy:deploy-file -DrepositoryId=releases -DartifactId=... -Durl=



回答2:


Over here, I used the GMaven plugin to choose the repository from the distributionManagement section of the POM and store it in a property.

The deploy plugin can then use that property.




回答3:


Maybe you want to use the build-helper-maven-plugin to deploy an additional artifact




回答4:


This is presumably the Maven way:

  <distributionManagement>
    <repository>
      <id>release</id>
      <url>http://my-releases</url>
    </repository>
    <snapshotRepository>
      <id>snapshots</id>
      <url>http://my-snapshots</url>
    </snapshotRepository>
  </distributionManagement>

When doing a deploy of a snapshot version, it'll go the snapshots repository. For a non-snapshot release the regular repository will be used.

Just run deploy and it'll work. :-)



来源:https://stackoverflow.com/questions/6871494/mvn-deployfile-to-different-repositories-for-snapshot-and-release-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!