0

我有一个关于使用父 POM 文件和子模块构建 Maven 站点的问题。当菜单从父 POM 继承时,我无法在继承的模块站点中获取相关链接。

我有一个项目结构如下:

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

因此,通过这种配置,我最终得到了一个如下所示的站点:

base-site/ 
    module1/
    module2/

从 modules/pom.xml 构建的 reactor 生成顶级网站,每个模块也生成一个网站。

每个模块都从父模块继承这个 site.xml 文件(例如):

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

引用标准 Maven 生成的“报告”的菜单工作正常。

但是 project-summary.html 的 href 最终指向顶部站点而不是子站点。

我在 Stackoverflow 上看到了一些与构建继承菜单有关的类似问题,但我没有找到有关如何让这些链接指向子站点而不是父站点中的内容的确切信息。我可能误解了菜单继承在这里应该完成的工作。

基本上,我希望子站点中生成的内容的菜单链接如下所示:

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

好的,所以我想,让我尝试使用过滤来完成这个,就像我的父 POM 使用类似的东西:

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

但这不起作用,因为父 POM 的名称在此处被替换,而不是子项目的名称。

在这种情况下,也许我需要为每个模块创建一个自定义 site.xml,但我想避免这种情况,因为其中有 15 个,并且它们在共享大约 8 或 9 个不同(相对) 菜单链接。大多数项目不需要自己的 site.xml 文件。所以理想情况下,我希望父级定义所有默认值,子级 POM 添加一些额外的菜单。

为了做到这一点,我是否坚持使用“报告”参考及其默认布局?或者我可以在父的 site.xml 文件中将这些明确列为菜单项并让这些引用以某种方式工作吗?

我希望这很清楚。谢谢。

4

1 回答 1

0

我和你有同样的需求。

我将 gmaven-plugin 与一个脚本(在生成资源阶段)一起使用,该脚本在父级中迭代并在当前项目中复制 src/site/site.xml(如果有)。

这是我的脚本(如果模块上存在“readme.md”文件,我只是在复制父 site.xml 文件):

<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>

问候

于 2014-11-18T10:43:14.480 回答