SAGARFIVE

Tutorials

4.4 Maven Site Lifecycle

  • Maven Site plugin is generally used to create fresh documentation to create reports, deploy site, etc. It has the following phases
  • pre-site
  • site
  • post-site
  • site-deploy

PhaseDescription
pre-siteexecute processes needed prior to the actual project site generation
sitegenerate the project’s site documentation
post-siteexecute processes needed to finalize the site generation, and to prepare for site deployment
site-deploydeploy the generated site documentation to the specified web server

Sample pom.xml for site life cycle :

<project xmlns = “http://maven.apache.org/POM/4.0.0”
   xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance”
   xsi:schemaLocation = “http://maven.apache.org/POM/4.0.0
   http://maven.apache.org/xsd/maven-4.0.0.xsd”>
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.companyname.projectgroup</groupId>
   <artifactId>project</artifactId>
   <version>1.0</version>
   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.7</version>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.9</version>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.1</version>
            <executions>
               <execution>
                  <id>id.pre-site</id>
                  <phase>pre-site</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <tasks>
                        <echo>pre-site phase</echo>
                     </tasks>
                  </configuration>
               </execution>
               
               <execution>
                  <id>id.site</id>
                  <phase>site</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <tasks>
                        <echo>site phase</echo>
                     </tasks>
                  </configuration>
               </execution>
               
               <execution>
                  <id>id.post-site</id>
                  <phase>post-site</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <tasks>
                        <echo>post-site phase</echo>
                     </tasks>
                  </configuration>
               </execution>
               
               <execution>
                  <id>id.site-deploy</id>
                  <phase>site-deploy</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <tasks>
                        <echo>site-deploy phase</echo>
                     </tasks>
                  </configuration>
               </execution>
               
            </executions>
         </plugin>
      </plugins>
   </build>
</project>

Output response :

C:\Users\gajan\artifactId-MavenApp> mvn site

[INFO] Scanning for projects…
[INFO]
[INFO] —————-< com.companyname.projectgroup:project >—————-
[INFO] Building project 1.0
[INFO] ——————————–[ jar ]———————————
[INFO]
[INFO] — maven-antrun-plugin:3.0.0:run (id.pre-site) @ project —
[INFO] Executing tasks
[WARNING]      [echo] pre-site phase
[INFO] Executed tasks
[INFO]
[INFO] — maven-site-plugin:3.7:site (default-site) @ project —
[WARNING] Input file encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[WARNING] No project URL defined – decoration links will not be relativized!
[INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.2 skin.
[INFO]
[INFO] — maven-antrun-plugin:3.0.0:run (id.site) @ project —
[INFO] Executing tasks
[WARNING]      [echo] site phase
[INFO] Executed tasks
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time:  4.323 s
[INFO] Finished at: 2021-12-10T20:22:31+05:30
[INFO] ————————————————————————

We can see the documentation like this :

Maven creates a site (documentation) within the target directory.

Maven creates the documentation using a documentation-processing engine called Doxia which reads multiple source formats into a common document model. To write documentation for your project, you can write your content in the following few commonly used formats which are parsed by Doxia.

Format NameDescriptionReference
XDocA Maven 1.x documentation formathttps://jakarta.apache.org/site
FMLUsed for FAQ documentshttps://maven.apache.org