8

我有一个包含很多子模块的 maven 项目,我使用父 pom 来控制插件,如下所示

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

因此src\site\site.xml包含如下自定义菜单

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

在我mvn site:stage以 root 运行后(从maven 站点插件建议),父网页很好,<sub-modules>\index.html而不包含任何菜单(没有项目信息和项目报告)

我还注意到,如果我mvn site在子模块下运行,则 index.html 左侧不包含任何菜单,而单个 html 存在于 pmd.html、license.html 等目录中

  • 我需要添加src\site\site.xml每个子模块还是其他更好的方式?
  • 还是我在pom.xml某个地方做了什么愚蠢的事情?

有什么提示吗?

[更新] 也喜欢横幅图像,如果我像这样在父级中设置

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

指向错误方向的子模块的站点,在 html 中,看起来像..\..\<submodule>,不是..\images\mylogo.png

4

4 回答 4

5

如果您想避免手动将 site.xml 复制到每个子模块,那么使用maven-resources-plugin可能是一种解决方法:将其添加到您的父 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>        

这对你的每个子模块 poms:

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

然后在创建站点文档之前,站点描述符将从父项目复制到每个子模块(覆盖现有描述符)。请注意,每个子模块中必须存在 src/site 目录才能使其工作。不是一个完美的解决方案,但可能比完整的手动解决方案更好。

于 2011-05-19T09:11:29.930 回答
5

site.xml可以使用该inherit属性从父级继承菜单。

例如,

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

现在所有子项目都将继承Overview和菜单。Development

有关更多详细信息,请参阅多模块站点的 Maven 文档, http ://maven.apache.org/plugins/maven-site-plugin/examples/multimodule.html#Inheritance

于 2015-01-07T12:15:00.077 回答
2

我在尝试生成多模块 Maven 站点时偶然发现了这一点,只是想分享我想出的解决方案。

在你的父母 pom 添加

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

到 Maven 站点插件配置。

这应该告诉所有子 pom 从父目录获取他们的 site.xml。

于 2015-12-18T14:48:36.500 回答
0

site.xml我正在使用一个从模板创建所有文件的小型 Python 脚本。这是要点

于 2013-03-11T09:50:09.987 回答