将javadoc附加到Maven部署

时间:2014-08-01 15:56:56

标签: maven-3 maven-deploy-plugin maven-javadoc-plugin

描述

我想通过mvn clean deploy在库本身的同时自动生成并部署到我的项目的javadoc。

首先尝试

我发现的示例,使用此POM提取在默认阶段(包)生成javadoc:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这对我来说并不完美,因为即使对于简单的mvn clean install,它也会消耗时间。

当前状态

我的想法是在执行时指定部署阶段:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

但问题是部署是在javadocs生成之前完成的,因此nexus只接收库...

如果我强制部署:部署阶段在javadoc阶段之后执行,我有2个部署阶段,第一个只发送lib而第二个可以发送lib + javadoc,因为已经发送了lib。 / p>

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

构建的摘录(SNAPSHOT与RELEASE):

(...)
--- maven-deploy-plugin:2.7:deploy (default-deploy) @ lib ---
Downloading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml
Downloaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml (758 B at 5.2 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.jar
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.jar (4 KB at 24.0 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.pom
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.pom (10 KB at 135.3 KB/sec)
Downloading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml
Downloaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml (482 B at 27.7 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml (758 B at 13.2 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml (482 B at 10.0 KB/sec)  
(...)

--- maven-javadoc-plugin:2.9.1:jar (attach-javadocs) @ lib ---

Loading source files for package lib...
(...)

SNAPSHOT:上传2次快照没问题

--- maven-deploy-plugin:2.7:deploy (deploy) @ lib ---
Downloading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml
Downloaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml (758 B at 37.0 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.jar
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.jar (4 KB at 68.6 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.pom
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3.pom (10 KB at 177.1 KB/sec)
Downloading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml
Downloaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml (482 B at 33.6 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml (758 B at 11.2 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/maven-metadata.xml (482 B at 13.8 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3-javadoc.jar
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/lib-1.4-20140804.085407-3-javadoc.jar (35 KB at 581.3 KB/sec)
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml
Uploaded: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4-SNAPSHOT/maven-metadata.xml (2 KB at 28.9 KB/sec)
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 7.342 s
Finished at: 2014-08-04T10:54:10+01:00
Final Memory: 36M/449M
------------------------------------------------------------------------

RELEASE:不允许重新部署

--- maven-deploy-plugin:2.7:deploy (deploy) @ lib ---
Uploading: Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4/lib-1.4.jar
Uploading: http://poc-nexus/content/repositories/poc-repo/poc/release/lib/1.4/lib-1.4.pom
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.403 s
Finished at: 2014-08-01T15:25:11+01:00
Final Memory: 24M/437M
------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (deploy) on project lib: Failed to deploy artifacts: Could not transfer artifact poc.release:lib:jar:1.4 from/to poc-repo (http://poc-nexus/content/repositories/poc-repo/): Failed to transfer file: http://poc-nexus/1.4/lib-1.4.jar. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]

如何在不创建特定构建配置文件的情况下执行此操作?

THKS。

1 个答案:

答案 0 :(得分:2)

我无法在javadoc插件之后重新排序部署插件的默认执行。但是,您可以跳过默认执行,这非常有用,因为非默认执行遵循POM中的顺序。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.10.3</version>
    <executions> 
        <execution> 
            <id>release</id>
            <phase>deploy</phase>
            <goals>
                <goal>jar</goal>
            </goals> 
        </execution> 
    </executions> 
</plugin>
<plugin> 
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId> 
    <version>2.8.2</version>
    <executions> 
        <execution> 
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
            <configuration>
                <skip>true</skip>
            </configuration> 
        </execution> 
        <execution> 
            <id>release</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy</goal>
            </goals> 
        </execution> 
    </executions> 
</plugin>

构建的摘录:

[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ AutoridadCertificanteHiba ---
[INFO] Skipping artifact deployment
[INFO] 
[INFO] --- maven-javadoc-plugin:2.10.3:jar (release) @ AutoridadCertificanteHiba ---
[INFO] 
[INFO] Building jar: /home/daniel/svnroot/firmaDigitalChrome/AutoridadCertificanteHiba/target/checkout/target/AutoridadCertificanteHiba-1.0.2-javadoc.jar
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (release) @ AutoridadCertificanteHiba ---
Uploading: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/1.0.2/AutoridadCertificanteHiba-1.0.2.jar               
Uploaded: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/1.0.2/AutoridadCertificanteHiba-1.0.2.jar (45 KB at 27.8 KB/sec)
Uploading: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/1.0.2/AutoridadCertificanteHiba-1.0.2.pom               
Uploaded: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/1.0.2/AutoridadCertificanteHiba-1.0.2.pom (13 KB at 18.4 KB/sec)
Downloading: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/maven-metadata.xml                
Downloaded: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/maven-metadata.xml (379 B at 2.3 KB/sec)
Uploading: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/maven-metadata.xml                
Uploaded: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/maven-metadata.xml (409 B at 1.2 KB/sec)
Uploading: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/1.0.2/AutoridadCertificanteHiba-1.0.2-javadoc.jar               
Uploaded: http://svn.hospitalitaliano.net:8080/archiva/repository/discomun-lib-releases/ar/org/hiba/dis/AutoridadCertificanteHiba/1.0.2/AutoridadCertificanteHiba-1.0.2-javadoc.jar (46 KB at 36.1 KB/sec)