让菜单继承在多模块Maven站点中工作



我有一个关于用父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生成的"报告"的菜单运行良好。

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

我在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添加一些额外的菜单。

为了做到这一点,我是否坚持使用"reports"ref及其默认布局?或者,我可以在父级的site.xml文件中将这些明确列为菜单项,并以某种方式使这些引用发挥作用吗?

我希望这是清楚的。谢谢

我和你有同样的需求。

我将使用gmaven插件和一个脚本(在生成资源阶段),该脚本在parent中迭代,并在当前项目中复制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>

问候

最新更新