Cyril
Cyril

Reputation: 21

Attaching javadocs to Maven deploy

Description

I would like to automatically generate and deploy to nexus the javadocs of my projects at the same time of the library itself by a mvn clean deploy.

First try

The example i've found, generate the javadoc during the default phase (package) with this POM extract :

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

This isn't perfect for me because it consume time even for a simple mvn clean install.

Current status

My idea was to specify the deploy phase en the execution :

<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>

But the matter is that the deploy is done before the javadocs generation, so nexus receive only the library...

And if I force the deploy:deploy phase to be executed after the javadoc phase, I have 2 deploy phase , the first one that send only lib and the second one that can send lib+javadoc because lib is already sent.

<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>

Extract of the builds (SNAPSHOT Vs 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 : No problem of uploading 2 times a snapshot

--- 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 : redeploy not allowed

--- 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]

How can I do this without having to create a specific build profile ?

Thks.

Upvotes: 2

Views: 3787

Answers (1)

Daniel Cretton
Daniel Cretton

Reputation: 21

I couldn't manage to reorder the default execution of the deploy plugin after the javadoc plugin. But, you can skip the default execution, wich is useful because the non default execution respects the order in the 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>

Extract of the build:

[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)

Upvotes: 2

Related Questions