Login  Register

Re: About Asciidoctor Maven integration: A custom lifecycle

Posted by rrialq on Aug 12, 2019; 12:52pm
URL: https://discuss.asciidoctor.org/About-Asciidoctor-Maven-integration-A-custom-lifecycle-tp7063p7069.html

The custom lifecycle I have developed define several phases, but only one of them is associated to a Mojo.
Why?
Because in this state is only a proof of concept, to take a look the pros and cons, and for resolving my particular needs.

So the decission about if you deploy a zip file to a repository, upload the html files generated, the pdf or if you want to attach the result of zip the generated files is customizable. How? In the same way as with another plugins:
with the executions.

The lifecycle will simplify the settings, and the lifecycle of the main artifacts will be independent from the build of the documentation.

For example, before that lifecycle, for downloading a pdf theme for Asciidoctor I wrote a configuration similar to:

   
    <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>${plugin-version.maven-dependency}</version>
        <executions>
            <execution>
               
                <id>asciidoctor-theme-unpack</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifact>com.coutemeier.mydoctor.theme:mydoctor-pdf-theme:1.0-SNAPSHOT</artifact>
                    <outputDirectory>${project.build.directory}/mydoctor-themes</outputDirectory>
                    <overWriteIfNewer>true</overWriteIfNewer>
                    <overWriteSnapshots>true</overWriteSnapshots>
                </configuration>
            </execution>
        </executions>
    </plugin>

   
    <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>wagon-maven-plugin</artifactId>
         <version>${version.mohojaus-wagon}</version>
         <executions>
             <execution>
                 <id>upload-to-nexus</id>
                 <phase>deploy</phase>
                 <goals>
                     <goal>upload</goal>
                 </goals>
                 <configuration>
                     <includes>**/*</includes>
                 </configuration>
             </execution>
         </executions>
    </plugin>

Take care of prepare-package, or replace it with another phase of the default lifecycle.
When you execute a mvn package, in a multimodule, and you want build everything except documentation, your only help is the use of profiles.

If you are working on the asciidoctor documentation, and you want to build it (but not the rest) you have a problem: you need to configure your pom with multiple profiles and properties to get it. This is not practical, neither easy to mantain.

With the new lifecycle you can configure as:

   
    <plugin>
        <groupId>com.coutemeier.maven.plugins</groupId>
        <artifactId>mydoctor-maven-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <extensions>true</extensions>
        <configuration>
            <themes>
                <theme>com.coutemeier.mydoctor.theme:mydoctor-pdf-theme:1.0-SNAPSHOT</theme>
            </themes>
            </themesBaseDir>${project.build.directory}/mydoctor-themes</themesBaseDir>
        </configuration>
    </plugin>

    <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>wagon-maven-plugin</artifactId>
         <version>${version.mohojaus-wagon}</version>
         <executions>
             <execution>
                 <id>upload-to-nexus</id>
                 <phase>upload</phase>
                 <goals>
                     <goal>upload</goal>
                 </goals>
                 <configuration>
                     <includes>**/*</includes>
                 </configuration>
             </execution>
         </executions>
    </plugin>

So when I execute mvn package it will package the project, but will not process the asciidoctor documentation.
And when I execute mvn build it will process the asciidoctor documentation, but will not compile or package the project.
In the same way as the site lifecycle.

If I want doing all the work, mvn upload will do all the work for asciidoctor documentation, including the upload to the Nexus repository site.

Of course, you can configure other plugins to upload to another repository, with another protocol (http, ssh, webdav...), and binding to the phase upload to to this job.

And I want to include another features:
* Packing the generated files as a new goal, may be using the zip goal of asciidoctor-maven-plugin: write less configuration.
* Define what is an mydoctor theme, the structure, the contents... may be in the future, not now. For the moment a theme is only a zip file with some contents that you will use as you want.
* Write a mojo to upload the generated files to a server...