24

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

extorn
  • 611
  • 1
  • 5
  • 11
  • Why do you like to do this for deploy:file ? Aren't you using mvn release:prepare and release:perform? – khmarbaise Jul 29 '11 at 10:25
  • I don't understand maven fully yet, but we're trying to migrate a complex ant build so that it uses maven to manage the dependencies and post the ant generated artifact. maven target deploy:file seemed the easiest way of specifying the file we wanted to deploy. – extorn Aug 15 '11 at 16:43
  • The idea in Maven for release is to deploy artifacts to the release repository (defined by the distributionManagement area) with possible supplemental artifacts (like javadoc, sources etc.). During the release process the version like 1.2.3-SNAPSHOT will be changed to 1.2.3 and the pom's etc will automatically updated and the next dev step will be incremented to (1.2.4-SNAPSHOT) whereas the 1.2.3 artifacts will be compiled, tested etc. and deployed to the release repository. – khmarbaise Aug 15 '11 at 16:46
  • That's true. But what we're trying to achieve here is the deployment of an ant generated artifact into the maven repository. We maintain two independant repositories, one for snapshots and one for releases. The idea was for the ant generated artifact to be deployed to the appropriate one based on an external enviornment property passed into maven as a system property. – extorn Aug 15 '11 at 16:51
  • 3
    what i don't understand is why you must specify the url of the repository in addition to the id when the url can be looked up from the settings.xml configuration file using the id. – extorn Aug 15 '11 at 16:59

4 Answers4

11

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

mvn deploy:deploy-file -DrepositoryId=releases -DartifactId=... -Durl=
michas
  • 25,361
  • 15
  • 76
  • 121
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
5

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.

Community
  • 1
  • 1
Urs Reupke
  • 6,791
  • 3
  • 35
  • 49
0

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

pitseeker
  • 2,535
  • 1
  • 27
  • 33
keiki
  • 3,260
  • 3
  • 30
  • 38
-3

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. :-)

Jan Goyvaerts
  • 2,913
  • 4
  • 35
  • 48
  • 9
    Unfortunately, ``deploy:deploy-file`` does not care about the settings in ``distributionManagement`` but instead expects you to specify the URL you want to deploy to. – Urs Reupke Nov 30 '12 at 12:36