Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy the sources file with the jar using deploy:deploy-file

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?

like image 961
Yoztastic Avatar asked Feb 20 '12 10:02

Yoztastic


People also ask

How do I deploy my jar in my remote repository?

To deploy a 3rd party JAR use the deploy:deploy-file goal under maven-deploy-plugin. First, the wagon-provider(wagon-ftp, wagon-file, etc..) must be placed to your ${maven. home}/lib .

Can we deploy jar file server?

To run a jar: java -jar server. jar. You have to copy the jar file to the server and run it. In case it's a web application you have to publish the war or ear.


2 Answers

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.

like image 145
Andrew Logvinov Avatar answered Sep 19 '22 20:09

Andrew Logvinov


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.
like image 32
joshm Avatar answered Sep 20 '22 20:09

joshm