-1

Deployment team require that we package our maven site as a war and publish it in Archiva repository.

Our first problem, how to assembly the war, with the children sites inside.

I try this, but it is not working. The war generated does not include children sites. I research in maven documentation, google, in stackoverflow, etc.. and I don't found anything.

Project structure folder:

.
├── child-yyyy-1
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── com
│       │           └── xxx
│       │               └── App.java
│       └── test
│           └── java
├── child-yyyy-2
│   ├── pom.xml
│   └── src
│       ├── main
│       │   └── java
│       │       └── com
│       │           └── xxx
│       │               └── App.java
│       └── test
│           └── java
└── parent-site
    ├── assembly
    │   └── api-site.xml
    └── pom.xml

parent pom:

<?xml version="1.0" encoding="UTF-8"?>
<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.xxx</groupId>
  <artifactId>parent-yyyy</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>parent-yyyy</name>

  <modules>
    <module>../child-yyyy-1</module>
    <module>../child-yyyy-2</module>
  </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>assembly/api-site.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

api-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=" http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>api-site</id>
    <formats>
        <format>war</format>
    </formats>
    <baseDirectory>/</baseDirectory>
    <fileSets>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>target/site</directory>
        </fileSet>
        <fileSet>
            <outputDirectory>/child-yyyy-1/</outputDirectory>
            <directory>child-yyyy-1/target/site</directory>
        </fileSet>
        <fileSet>
            <outputDirectory>/child-yyyy-2/</outputDirectory>
            <directory>child-yyyy-2/target/site</directory>
        </fileSet>
    </fileSets>
</assembly>

child 1 pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.xxx</groupId>
    <artifactId>parent-yyyy</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../site</relativePath>
  </parent>
  <groupId>com.xxx</groupId>
  <artifactId>child-yyyy-1</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>child-yyyy-1</name>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

child 2 pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.xxx</groupId>
    <artifactId>parent-yyyy</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../site</relativePath>
  </parent>
  <groupId>com.xxx</groupId>
  <artifactId>child-yyyy-2</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>child-yyyy-2</name>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>
angelcervera
  • 3,699
  • 1
  • 40
  • 68

1 Answers1

1

First is you have the wrong project structure which means you have your parent in a subfolder...better is having the parent like this.

  +-- parent (pom.xml)
       +--- child1 (pom.xml)
       +--- child2 (pom.xml)
       ....

This will simplify your parent you don't need to give ../ for modules...and in the childs you don't need to give a relativePath elements in parent.

Apart from that defining maven-assembly-plugin in parent does not make sense cause the parent will be executed first which means at that time you don't have generated the sites.

The default solution for this is to create a separate child

  +-- parent (pom.xml)
       +--- child1 (pom.xml)
       +--- child2 (pom.xml)
       +--- site-child (pom.xml)

Define the maven-assembly-plugin as you did and very important define dependencies to the childs of their sites you would like to include.

From all the above a site is generated by using:

mvn site

which means you are in the site life cycle which means you need to packagage the war in the site life cycle and not in the default life cycle os you need to change your configuration for maven-assembly-plugin from this:

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>assembly/api-site.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

to the following:

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>assembly/api-site.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <phase>site</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

After this should be able to create this via:

mvn site
khmarbaise
  • 92,914
  • 28
  • 189
  • 235