7

I have a maven project with lots of sub-modules, and I use parent pom to control the plugins the directory like below

-pom.xml (parent pom)
 +- submodule1
 +- submodule2
 +- src\site\site.xml

therefore src\site\site.xml contains the customized menu like below

<project>
  ....
  <body>
   <menu name="Overview">
    <item name="Introduction" href="introduction.html"/>
   </menu>
   <menu name="Development">
      <item name="Getting started" href="designenv.html"/>
      <item name="FAQ" href="designfaq.html" />
      <item name="Javadoc" href="apidocs/index.html" />
   </menu>
   <menu ref="modules"/>
   <menu ref="reports"/>
 </body>
</project>

After I run mvn site:stage in root (suggested from maven site plugin), the parent webpage is fine, while the <sub-modules>\index.html doesn't contain any menu (no project info & project report)

Also I notice if I run mvn site under sub-modules, the index.html doesn't contain any menu in left, while the individual html exist in directory like pmd.html, license.html

  • Do I need to add src\site\site.xml in each sub-module or other better way ?
  • or Did I do something stupid in pom.xml somewhere ?

Any hints ?

[update] also like for banner image, if I set in parent like this

<bannerLeft>
  <name>edcp</name>
  <src>images/mylogo.png</src>
</bannerLeft>

The site for sub-module with points to wrong direction, in html, looks like ..\..\<submodule>, not ..\images\mylogo.png

Larry Cai
  • 45,222
  • 30
  • 104
  • 141
  • If I add simple site.xml under each submodule, it works fine now – Larry Cai May 13 '11 at 02:59
  • You could answer your own question and select it as correct. This way it would be visible from the overview pages that the question has a solution. – Jan May 16 '11 at 08:22
  • it is a not a good solution as I expected, and I still want to have people to give me better answer, and this system recommend not to answer my own question. – Larry Cai May 18 '11 at 03:03
  • Ok, that's fine so far (if you still want to get answers) - but then you first comment is misleading ;-) – Jan May 19 '11 at 07:07

4 Answers4

5

It's possible to inherit menus from the parent site.xml by using the inherit attribute.

E.g,

<project>
  ....
  <body>
   <menu name="Overview" inherit="top">
    <item name="Introduction" href="introduction.html"/>
   </menu>
   <menu name="Development" inherit="top">
      <item name="Getting started" href="designenv.html"/>
      <item name="FAQ" href="designfaq.html" />
      <item name="Javadoc" href="apidocs/index.html" />
   </menu>
   <menu ref="modules"/>
   <menu ref="reports"/>
 </body>
</project>

Now both the Overview and Development menus will be inherited by all sub-projects.

See the Maven documentation for multi-module sites for more details, http://maven.apache.org/plugins/maven-site-plugin/examples/multimodule.html#Inheritance

fluffy88
  • 69
  • 1
  • 6
4

If you would like to avoid copying the site.xml to each submodule manually, then using the maven-resources-plugin could be a workaround: Add this to your parent pom:

[...]
<properties>
    <site.basedir>${project.basedir}</site.basedir>
</properties>
[...]
<build> 
 <plugins>
  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>
      <execution>
        <id>copy-sitedescriptor</id>
        <!-- fetch site.xml before creating site documentation -->
        <phase>pre-site</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/src/site/</outputDirectory>
          <resources>          
            <resource>                  
              <directory>${site.basedir}/src/site/</directory>
              <includes>
                <include>**/site.xml</include>
              </includes>
            </resource>
          </resources>              
        </configuration>            
      </execution>
    </executions>
   </plugin>        

and this to each of your submodule poms:

<properties>
    <site.basedir>${project.parent.basedir}</site.basedir>
</properties>

Then the site descriptor will be copied from the parent project to each submodule (overwriting existing descriptors) before the site documentation is created. Please note that the src/site directory must exist in each submodule to make this work. Not a perfect solution, but maybe better than a complete manual one.

dbenz
  • 56
  • 2
  • Possibly superseded by the accepted answer here: http://stackoverflow.com/questions/10848715/multi-module-pom-creating-a-site-that-works – Stewart Jun 23 '13 at 21:05
2

I stumbled across this when trying to generate a multi module maven site and just wanted to share a solution I came up with.

In your parent pom add

<siteDirectory>${session.executionRootDirectory}/src/site</siteDirectory>

to the maven site plugin configuration.

That should tell all the child poms to get their site.xml from the parent directory.

Ben
  • 1,265
  • 1
  • 9
  • 15
  • However, this will completely ignore whatever is specific for the child modules. First I also thought this would be the solution, but it does something slightly different. – Honza Zidek Jan 06 '17 at 13:22
0

I'm using a small Python script that creates all the site.xml files from a template. Here is the gist.

Aaron Digulla
  • 297,790
  • 101
  • 558
  • 777