Question

I have a question about constructing a Maven site with a parent POM file and sub-modules. I am having trouble getting relative links in inherited module sites to work when the menu is inherited from a parent POM.

I have a project structure as follows:

modules/pom.xml
    parent/
    module1/
    module2/
    etc.

So with this configuration I end up with a site that looks like:

base-site/ 
    module1/
    module2/

The reactor build from modules/pom.xml generates the top-level website, and each of the modules also has a site generated.

Each of the modules inherits this site.xml file from the parent (for example):

<project>
    <body>
        <menu name="Module" inherit="top">
            <item name="Summary" href="./project-summary.html"/>
        </menu>
        <menu name="Module" ref="reports" inherit="bottom" />
    </body>
</project>

The menu referencing the standard Maven generated "reports" works fine.

But the href to project-summary.html ends up pointing back at the top site and not the child.

I have seen some similar issues on Stackoverflow having to do with constructing an inherited menu, but I did not find exact information on how to get these links to point to content in the child site and not the parent. It may be possible that I am misunderstanding what the menu inheritance is supposed to accomplish here.

Basically, I want the menu links to generated content in the child sites to look like:

<item name="Summary" href="./module1/project-summary.html"/>

Okay, so I thought, let me try to use filtering to accomplish this like from my parent POM using something like:

<item name="Summary" href="./${project.artifactId}/project-summary.html"/>

But that does not work because the parent POM's name gets substituted here instead of the child project's name.

In this case, perhaps I need site a custom site.xml for each module, but I would like to avoid this as there are something like 15 of them, and they will mostly be identical in terms of sharing about 8 or 9 different (relative) menu links. Most projects would not need their own site.xml file. So ideally I'd like the parent to define all the defaults with the child POMs adding a few additional menus.

In order to do this, am I stuck with using the "reports" ref and its default layout? Or can I list these explicitly as menu items in the parent's site.xml file and get those references to work somehow?

I hope that's clear. Thanks.

No correct solution

OTHER TIPS

I've the same need as you.

I'll use the gmaven-plugin with a script (during the generate resource phase) that iterates in parent and copy src/site/site.xml in the current project if any.

Here's my script (Here's I'm just copying a parent site.xml file if a 'readme.md' file is present on the module):

<plugin>
                    <groupId>org.codehaus.gmavenplus</groupId>
                    <artifactId>gmavenplus-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <phase>pre-site</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <scripts>
                            <script> <![CDATA[ 
                            import java.io.BufferedWriter
                            import java.io.File
                            import java.nio.charset.Charset
                            import java.nio.file.StandardCopyOption
                            import java.nio.file.Files
                            import java.nio.file.StandardOpenOption
                            String siteXmlPath = "src/site/site.xml"
                            String readme_file = "readme.md"
                            String currentPath = "${project.basedir}"
                            if (new File(currentPath + "/" + readme_file).exists() && !(new    File(currentPath + "/" + siteXmlPath).exists())) { 
                                while (!(new File(currentPath + "/" + siteXmlPath).exists())) {
                                    currentPath = currentPath + "/.." 
                                    if (new File(currentPath + "/" + siteXmlPath).exists()) { 
                                        Files.copy(new File(currentPath + "/" + siteXmlPath).toPath(), new File("${project.basedir}/" + siteXmlPath).toPath(), StandardCopyOption.REPLACE_EXISTING)
                                        File newlyCreatedFile = new File("${project.basedir}/" + siteXmlPath)
                                        BufferedWriter newFileWriter = Files.newBufferedWriter(newlyCreatedFile.toPath(), Charset.defaultCharset(), StandardOpenOption.APPEND)
                                        newFileWriter.append("<!-- @generated -->")
                                        newFileWriter.close() 
                                    } else if (!(new File(currentPath + "/pom.xml").exists())) { break; } 
                                } 
                            } ]]>
                            </script>
                        </scripts>
                    </configuration>
                </plugin>

Regards

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top