How to deploy SNAPSHOT with sources and JavaDoc?

JavaMaven 2Maven Release-Plugin

Java Problem Overview


I want to deploy sources and javadocs with my snapshots. This means that I want to automize the following command:

mvn clean source:jar javadoc:jar deploy

Just to execute:

mvn clean deploy

I don't want to have javadoc/sources generation executed during the install phase (i.e. local builds).

I know that source/javadoc plugins can be synchronized with the execution of the release plugin but I can't figure out how to wire it to the snapshots releases.

Java Solutions


Solution 1 - Java

<build>
  <plugins> 
    <plugin>
      <artifactId>maven-source-plugin</artifactId>
      <executions>
        <execution>
          <id>attach-sources</id>
          <phase>deploy</phase>
          <goals><goal>jar-no-fork</goal></goals> 
        </execution>
      </executions>
    </plugin>
    <plugin> 
      <artifactId>maven-javadoc-plugin</artifactId> 
      <executions> 
        <execution> 
          <id>attach-javadocs</id>
          <phase>deploy</phase>
          <goals><goal>jar</goal></goals> 
        </execution> 
      </executions> 
    </plugin>
    <plugin> 
      <!-- explicitly define maven-deploy-plugin after other to force exec order -->
      <artifactId>maven-deploy-plugin</artifactId> 
      <executions> 
        <execution> 
          <id>deploy</id>
          <phase>deploy</phase>
          <goals><goal>deploy</goal></goals> 
        </execution> 
      </executions> 
    </plugin>
  </plugins> 
</build>

See Sonatype's OSS parent POM for a complete example.

Solution 2 - Java

The article referred to by Dan also mentions another approach that works without modifying poms AND won't go away anytime soon:

> mvn clean javadoc:jar source:jar install

Which works fine with Maven 3+, along with...

> mvn clean javadoc:jar source:jar deploy

Which I have tested from Jenkins deploying to Nexus.

This approach was nice because I only had to modify some Jenkins jobs and didn't need to mess with my poms.

Solution 3 - Java

Just to add an alternative that doesn't require you to muck with plugin configuration:

mvn -DperformRelease=true [goals]

Credit goes to mcbeelen from http://sea36.blogspot.com/2009/02/attaching-javadocs-and-sources-to-maven.html?showComment=1314177874102#c6853460758692768998

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHenryk KonsekView Question on Stackoverflow
Solution 1 - JavasfusseneggerView Answer on Stackoverflow
Solution 2 - JavaHDaveView Answer on Stackoverflow
Solution 3 - JavaDanView Answer on Stackoverflow