11

I have the following plugins for creating a -sources.jar and deploying a specific named jar to a repository.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <executions>
        <execution>
            <id>attach-sources</id>
            <goals>
                <goal>jar</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <version>${project.version}-r${buildNumber}</version>
        <classifier>${env}</classifier>
        <packaging>jar</packaging>
        <file>${project.build.directory}/${project.build.finalName}.jar</file>
        <url>${artifactory.url}/libs-release-local</url>
        <repositoryId>artifactory.digiterre.com</repositoryId>
        <pomFile>${project.basedir}/pom.xml</pomFile>
    </configuration>
</plugin>

I wish to deploy the *-sources.jar at the same time. I have tried adding a second file entry and even a second deploy plugin. I seem to get one or other file deployed.

Is it possible to deploy both in one pass using deploy:deploy-file or will I have to set up a second team city build just to deploy the sources?

MTranchant
  • 485
  • 1
  • 7
  • 23
Yoztastic
  • 792
  • 1
  • 6
  • 20
  • Duplicate of http://stackoverflow.com/questions/4725668/how-to-deploy-snapshot-with-sources-and-javadoc ? – Paul Grime Feb 20 '12 at 10:40
  • I have looked at that post and tried the suggestions. Neither work as I am deploying a file with specific classifier. Also jar-no-fork does not work Maven throws an error. – Yoztastic Feb 20 '12 at 10:53
  • It's a bit dirty, but maybe use an Ant task from Maven that executes a deploy from the command line? – Paul Grime Feb 20 '12 at 11:03
  • I am not using any pom.xml file , from jenkin how I will pass the version number dynamically.Suggest me. – JDGuide Jan 16 '14 at 13:07

3 Answers3

8

When you use maven-source-plugin, the generated jar will automatically attach to project artifact (default setting for this parameter is 'true') and if you execute deploy it will be deployed along with it. Alas, no need for separate configuration of deploy plugin.

Unfortunately, you cannot add classifier (${env} in your case) to sources jar. That is why I'd use the following configuration:

...
<artifactId>com.pie.mash.repo.mince-${env}</artifactId>
<version>1.18-r${buildNumber}</version>
...
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.1.2</version>
      <executions>
        <execution>
          <goals>
            <goal>jar-no-fork</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Also, I've found this question on SO. You can use the workaround suggested there.

Community
  • 1
  • 1
Andrew Logvinov
  • 18,809
  • 4
  • 48
  • 50
  • using 2.1.2 version explicitly does not throw the error I was getting previously. – Yoztastic Feb 20 '12 at 14:21
  • However, the sources still do not get deployed using this example. – Yoztastic Feb 20 '12 at 14:21
  • @Yoztastic You should invoke `mvn clean deploy`. And, as I've already mentioned, there is no need for separate configuration of deploy plugin. – Andrew Logvinov Feb 20 '12 at 17:12
  • removing the maven-deploy-plugin altogether fails to resolve dependencies to maven-deploy-plugin v2.4. Leaving the existing one in but removing the configuration section results in uploading jar and sources jar but with the r* and $env sections missing. It is odd because in target the correct files get created with the correct names. – Yoztastic Feb 20 '12 at 17:39
  • @Yoztastic Can you provide a log file of `mvn deploy`? – Andrew Logvinov Feb 20 '12 at 19:32
  • [https://docs.google.com/document/d/1A4BoVAn9rLqvK4ZUCTJ8q6axGMRAYUWAxMHZLcgVN70/edit?pli=1](log.txt) note **com.pie.mash.repo.mince-1.18-r5135-pie_gravy.jar** is the desired name **com.pie.mash.repo.mince-1.18-sources.jar** gets uploaded – Yoztastic Feb 21 '12 at 09:45
  • this will not work as **r${buildNumber}** will not be known in the context of **1.18-r${buildNumber}** it only becomes available later. – Yoztastic Feb 21 '12 at 12:54
  • Sadly for you, it won't work then. Take a close look at log you provided above - `com.pie.mash.repo.mince-1.18.jar` gets deployed. This is because Maven takes coordinates from project and in project you have `1.18`. – Andrew Logvinov Feb 21 '12 at 13:39
  • so strange that it has no trouble copying the correct files to the target dir but cant upload them to Artifactory. Really disappointing must have spent over a day on this and what should have been a small incremental step has gone nowhere. Thanks for your persistence. – Yoztastic Feb 21 '12 at 13:56
3

We can use deploy:deploy-file to upload multiple JARs (sources, tests, docs) along side main JAR artifact. We just need to supply that additional piece of information to deploy:deploy-file plugin call. The additions are indicated in bold in below command:

mvn deploy:deploy-file
-Dfile=helloWorld.jar
-Durl=https://localhost/nexus/content/repositories/snapshots/
-DrepositoryId=snapshot
-Dfiles=helloWorld-6.4.1.3.SNAPSHOT-sources.jar,helloWorld-6.4.1.3.SNAPSHOT-tests.jar
-Dtypes=jar,jar -Dclassifiers=sources,tests
-DgroupId=com
-DartifactId=helloWorld
-Dversion=6.4.1.3.SNAPSHOT
-Dpackaging=jar
-Dpomfile=pom.xml

  • We need to specify list of files separated by commas.
  • We need to specify the types of those additional files.
  • We need to add classifier information for those additional files.
sschmeck
  • 5,803
  • 2
  • 30
  • 53
joshm
  • 71
  • 5
1

mvn deploy:deploy-file only deploys a single artifact. Instead you can use mvn deploy (which invokes mvn deploy:deploy) to deploy the artifact, its pom along with the attached artifacts (like source and javadoc). Refer to the goals overview of maven deploy plugin.

Raghuram
  • 49,195
  • 9
  • 101
  • 120
  • I am using deploy:deploy-file url=http://repo.xxx.xxx.com/content/repositories/peroo-snapshots/ repositoryId=peroo-snapshots groupId=com.xxx.ist.curo.testtalentClient artifactId=pet_client_osx version=${CLIENT_VERSIONCITEST}.0-SNAPSHOT packaging=tar classifier=Rev_${SVN_REVISION} file=$WORKSPACE/CWave3/TalentOSX/build/Release/Talent.app.tar – JDGuide Jan 16 '14 at 13:08
  • CLIENT_VERSIONCITEST environment variable should change every time, but its not working on jenkins. – JDGuide Jan 16 '14 at 13:10