如何使用源代码和 JavaDoc 部署 SNAPSHOT?

我想用我的快照部署源代码和 javadocs:

mvn clean source:jar javadoc:jar deploy

执行:

mvn clean deploy

我不希望在 install阶段(即本地构建)执行 javadoc/source 生成。

我知道 source/javadoc 插件可以与 release插件的执行同步,但是我不知道如何将它连接到快照版本。

52854 次浏览
<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.

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

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.