【问题标题】:maven site for multi module多模块的maven站点
【发布时间】:2011-05-12 09:42:45
【问题描述】:

我有一个包含很多子模块的 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 后(来自maven site plugin 的建议),父网页很好,而&lt;sub-modules&gt;\index.html 不包含任何菜单(没有项目信息和项目报告)

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

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

有什么提示吗?

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

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

指向错误方向的子模块的站点,在 html 中,看起来像 ..\..\&lt;submodule&gt;,而不是 ..\images\mylogo.png

【问题讨论】:

  • 如果我在每个子模块下添加简单的 site.xml,它现在可以正常工作
  • 您可以回答自己的问题并选择正确。这样就可以从概述页面中看到问题有解决方案。
  • 这不是我预期的好解决方案,我仍然希望有人给我更好的答案,这个系统建议不要回答我自己的问题。
  • 好的,到目前为止还不错(如果您仍想获得答案)-但是您的第一个评论具有误导性;-)

标签: maven-2 maven-site-plugin


【解决方案1】:

如果您想避免手动将 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 目录才能使其工作。不是一个完美的解决方案,但可能比完整的手动解决方案更好。

【讨论】:

【解决方案2】:

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

例如,

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

现在OverviewDevelopment 菜单都将被所有子项目继承。

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

【讨论】:

    【解决方案3】:

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

    在你的父 pom 中添加

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

    到 Maven 站点插件配置。

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

    【讨论】:

    • 但是,这将完全忽略子模块的特定内容。首先,我也认为这将是解决方案,但它的作用略有不同。
    【解决方案4】:

    我正在使用一个小的 Python 脚本,它从模板创建所有 site.xml 文件。 Here is the gist.

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-26
      • 2014-03-23
      • 1970-01-01
      相关资源
      最近更新 更多