多模块 Maven 站点

发布于 2024-11-06 08:00:22 字数 1462 浏览 5 评论 0原文

我有一个包含很多子模块的 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>

在我运行 <根目录中的 code>mvn site:stage (来自 maven site插件),父网页很好,而 \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 中,看起来像 ..\..\ ,而不是 ..\images\mylogo.png

I have a maven project with lots of sub-modules, and I use parent pom to control the plugins the directory like below

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

therefore src\site\site.xml contains the customized menu like below

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

After I run mvn site:stage in root (suggested from maven site plugin), the parent webpage is fine, while the <sub-modules>\index.html doesn't contain any menu (no project info & project report)

Also I notice if I run mvn site under sub-modules, the index.html doesn't contain any menu in left, while the individual html exist in directory like pmd.html, license.html

  • Do I need to add src\site\site.xml in each sub-module or other better way ?
  • or Did I do something stupid in pom.xml somewhere ?

Any hints ?

[update] also like for banner image, if I set in parent like this

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

The site for sub-module with points to wrong direction, in html, looks like ..\..\<submodule>, not ..\images\mylogo.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻找一个思念的角度 2024-11-13 08:00:22

如果您想避免手动将 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>        

并将其添加到每个子模块 pom:

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

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

If you would like to avoid copying the site.xml to each submodule manually, then using the maven-resources-plugin could be a workaround: Add this to your parent 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>        

and this to each of your submodule poms:

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

Then the site descriptor will be copied from the parent project to each submodule (overwriting existing descriptors) before the site documentation is created. Please note that the src/site directory must exist in each submodule to make this work. Not a perfect solution, but maybe better than a complete manual one.

洋洋洒洒 2024-11-13 08:00:22

可以使用 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#继承

It's possible to inherit menus from the parent site.xml by using the inherit attribute.

E.g,

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

Now both the Overview and Development menus will be inherited by all sub-projects.

See the Maven documentation for multi-module sites for more details,
http://maven.apache.org/plugins/maven-site-plugin/examples/multimodule.html#Inheritance

强者自强 2024-11-13 08:00:22

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

在您的父 pom 中添加

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

到 Maven 站点插件配置。

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

I stumbled across this when trying to generate a multi module maven site and just wanted to share a solution I came up with.

In your parent pom add

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

to the maven site plugin configuration.

That should tell all the child poms to get their site.xml from the parent directory.

佼人 2024-11-13 08:00:22

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

I'm using a small Python script that creates all the site.xml files from a template. Here is the gist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文