我有一个多模块应用程序,我正在尝试为这个应用程序生成一个Maven站点。
我有一个包含所有子模块的聚合 POM,一个包含子模块的所有常见功能的继承 POM,以及一个大约 20 个子模块。
我已经循环浏览了无穷无尽的在线示例,了解如何使其工作。在这些中,多模块部分都不起作用。我可以在子级的目标/站点文件夹(和聚合模块)中构建单个站点输出。我还将其暂存到聚合 POM 中的目标/暂存文件夹中。创建的东西看起来不错。
但:
所有子模块链接都不起作用。
我尝试在码头下运行它,因为关于这个问题的一些评论说链接只有在它构建为网站时才有效——但不,同样的问题,它找不到孩子的索引.html。
有没有人有这样的例子?为了避免我扯掉更多的头发(上帝知道它已经在那里用完了),我宁愿看到实际的工作POM代码和/或纠正测试和部署所遵循的阶段。
谁能帮忙?
我找到了一个"更简单"的解决方案来配置stage
目标。 它将自动聚合${project.baseURI}/target/staging
文件夹中每个模块的文档。 诀窍是将其添加到所有子模块的父 pom 中:
<distributionManagement>
<site>
<id>${project.artifactId}-site</id>
<url>${project.baseUri}</url>
</site>
</distributionManagement>
跑
mvn clean site site:stage
来自 POM 聚合器。 然后查看target/staging
文件夹。您将正确链接子模块文档!
好的,终于可以工作了。
将此(仅)添加到父 POM,并根据需要更改暂存文件夹:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<stagingDirectory>C:tempstage</stagingDirectory>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration></configuration>
<reportSets>
<reportSet>
<id>non-aggregate</id>
<configuration>
<!-- Specific configuration for the aggregate report -->
<sourcepath>${project.build.sourceDirectory}/../generated</sourcepath>
</configuration>
<reports>
<report>javadoc</report>
</reports>
</reportSet>
<reportSet>
<id>aggregate</id>
<configuration>
<!-- Specific configuration for the aggregate report -->
<sourcepath>${project.build.sourceDirectory}/../generated</sourcepath>
</configuration>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.6</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
将此添加到父级的分发管理部分:
<site>
<id>${project.artifactId}-site</id>
<url>./</url>
</site>
然后运行
mvn site site:stage
这应该部署到具有工作链接的临时/站点中。
自上次解决方案以来已经一年多了。
我不喜欢这种解决方法,必须有另一种解决方案"maven 方式"。
所以这里是:
在 Maven 站点插件常见问题解答中:http://maven.apache.org/plugins/maven-site-plugin/faq.html#Use_of_url
"另一方面,在多模块构建中用于构建相对链接[...]。在多模块构建中,父模块和子模块具有不同的 URL 非常重要。
您必须在每个 pom 中声明
父聚甲醛:
<distributionManagement>
<site>
<id>mysite</id>
<name>My Site</name>
<url>ftp://server.example.com/htdocs/site/</url>
</site>
</distributionManagement>
儿童一聚甲酸:
<distributionManagement>
<site>
<id>mysite</id>
<name>My Site</name>
<url>ftp://server.example.com/htdocs/site/one/</url>
</site>
</distributionManagement>
儿童二聚甲醛:
<distributionManagement>
<site>
<id>mysite</id>
<name>My Site</name>
<url>ftp://server.example.com/htdocs/site/two/</url>
</site>
</distributionManagement>
现在,站点的生成和暂存按请求工作。暂存站点以parent/target/staging
生成
您可以使用 -D 提交另一个暂存目录
mvn -DstagingDirectory=D:/Temp/Site package site site:stage
注意:如果子项 2 具有子项 1 作为依赖项,则需要目标包。使用包,可以执行目标站点,而不会出现存储库中缺少依赖项的错误。
编辑:有必要为每个使用与
子链接在当前项目中不起作用,您需要做一个 site:stage,否则它将不起作用。您需要定义 stagingDirectory,该目录定义目标位置必须是绝对路径。
一些迷失者的指针。运行mvn site site:stage
后,site
目录将不包含组合站点,该站点将位于staging
目录中。根据 maven 站点插件使用页面,在部署站点之前不会完成组合。暂存后,您可以调用mvn site:deploy
将组合站点复制到您在分发管理中定义的 url 中指定的位置
<distributionManagement>
<site>
<id>website</id>
<url>file://${project.build.directory}/completesite</url>
</site>
</distributionManagement>
在这种情况下,完成的站点将最终位于项目构建目录(通常是target
目录)completesite
目录中。
这并不完全按照您的想法工作。这在运行"mvn 站点"时为什么父模块和子模块之间的链接不起作用?常见问题。
我不是Maven的专家,但这就是我在本地生成网站的方式:
在根 POM 中配置
<site>
<distributionManagement> <site> <id>internal.repo</id> <name>Temporary Staging Repository</name> <url>file://${project.build.directory}/mvn-repo</url> </site> </distributionManagement>
为项目构建网站
mvn site
生成本地暂存站点。这"根据 POM 部分中指定的站点 URL 将生成的站点部署到本地暂存或模拟目录。
mvn site:stage
默认情况下,站点将在
${project.build.directory}/staging
目录下生成
我有一个与 OP 类似的情况,但有一个转折:其中一个子模块不继承自多模块项目父模块。 我想生成一个具有所有链接正常工作的暂存站点。 以下是项目结构:
extraParent // parent not part of this multi-module build
foo
pom.xml // aggregator
fooParent // parent for this project
module1 // inherits from fooParent
extraModule // inherits from extraParent
@Stefan的回答是朝着正确方向迈出的一大步。 特别是,我确认子模块必须重复distributionManagement
和url
元素。 我在fooParent中尝试过这个:
<properties>
<foo.site.url>file://somePath/foo/${project.artifactId}</foo.site.url>
</properties>
<url>${foo.site.url}</url>
<distributionManagement>
<site>
<id>site-docs</id>
<url>${foo.site.url}</url>
</site>
</distributionManagement>
Maven 分别计算了 fooParent 和模块 1 中foo.site.url
的正确值:file://somePath/foo/fooParent
和 file://somePath/foo/module1
。 但是,顶级站点不包含指向模块 1 的正确链接,除非在子站点中复制了完全相同的 url/distributionManagement 块。 站点生成似乎正在检查继承的配置,而不考虑实际的 URL 值(即使它们在我查看有效 POM 时描述的情况下是不同的)。我发现这是非常不直观的。
我还需要一个配置元素来让顶级站点正确链接到 extraModule:topSiteURL
. 我将以下内容添加到extraModule的POM中。注意 我只是将 URL 的基部分(包括顶级目录)提取到 topSiteURL
值中,然后在 foo.site.url
属性中使用它。
<properties>
<topSiteURL>file://somePath/foo/</topSiteURL>
<foo.site.url>${topSiteURL}/${project.artifactId}</foo.site.url>
</properties>
<url>${foo.site.url}</url>
<distributionManagement>
<site>
<id>site-docs</id>
<url>${foo.site.url}</url>
</site>
</distributionManagement>
现在,当我使用 mvn site site:stage
为多模块项目生成站点时,所有链接都有效。
在 http://wiki.bitplan.com/index.php/Multi-Module_Maven_with_github_pages,您将在github-pages的上下文中找到详细的分析和示例。另请参阅将 mvn 站点部署与 github 页面一起使用的多模块示例
有什么解决方法?
- 不要使用插件!
- git 克隆或拉取 gh 页面到本地文件夹
- MVN 站点:暂存到临时暂存目录
- 将结果同步到 git 本地文件夹
- 签入本地文件夹 喝
杯咖啡或喝啤酒/快乐
不要使用插件!
它很慢(就像真的很慢...示例项目为 18 分钟)
它不可靠(如 500 HTML代码)
它没有得到很好的维护(如[https://github.com/github/maven-plugins/issues 截至 57 个未决问题2018年08月]
- 这是超级的(见下文)即使是提交者也不使用它不再(就像我今天收到的个人邮件一样.
#
# createSite
# ws: global variable pointing to workspace
# param 1: l_project - project name/directory
# param 2: l_ghpages - directory where gh-pages branch has been git cloned/pulled
# param 3: l_modules - non-empty for a multi-module project (e.g. containing the list of modules)
#
createSite() {
local l_project="$1"
local l_ghpages="$2"
local l_modules="$3"
color_msg $green "creating site for $l_project $l_modules"
cd $ws/$l_project
stage=/tmp/stage$$
sitelog=/tmp/sitelog$$.txt
rm -rf $stage
# the stagingDirectory needs to be subdirectory
mkdir -p $stage/$l_project
# run the staging of the site against this directory and log the results
mvn -U clean install site site:stage -DstagingDirectory=$stage/$l_project | tee $sitelog
# rsync the result into the github-pages folder
rsync -avz --del $stage/* $l_ghpages/$l_project/
# is this a multi module project?
if [ "$l_modules" != "" ]
then
cd $l_ghpages/$l_project/
if [ ! -f index.html ]
then
cat << EOF > index.html
<!DOCTYPE html>
<html>
<head>
<!-- HTML meta refresh URL redirection -->
<meta http-equiv="refresh"
content="0; url=./$l_project/$l_project/index.html">
</head>
<body>
<p>This is a multimodule mvn site click below to get to the index.html of
<a href="./$l_project/$l_project/index.html">$l_project</a></p>
</body>
</html>
EOF
fi
# add potentially new files
git add *
# commit results
git commit -m "checked in by checksite script"
# push results
git push
fi
if [ "$debug" = "false" ]
then
rm -rf $stage
rm $sitelog
fi
}
我的情况将以下部分添加到顶部pom解决了问题:
<distributionManagement>
<site>
<id>struts-site</id>
<url>https://struts.apache.org/maven/</url>
</site>
</distributionManagement>
现在使用以下命令,它将在target/staging
下生成整个页面:
./mvnw clean site site:stage
我正在使用这样的插件配置:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.0</version>
<configuration>
<relativizeDecorationLinks>false</relativizeDecorationLinks>
</configuration>
请注意,您还必须为每个子模块定义site.xml
,因为菜单不是继承的。