我不知道,如果这是一个好的解决方案,但没有其他答案,所以我想出了这个:
1。将程序集构建移动到单独的子模块中
重要提示:我不知道这是否有必要,但是如果在根项目中配置了程序集,我没有时间检查它是否也有效。否则,您必须在步骤 2 中使用不同的分类器定义 my-project 到 my-project 本身的依赖关系,我认为这不起作用。如果我错了,请随时编辑此答案。
+ my-project
+-- my-child-project-1
+-- my-child-project-2
+-- my-project-build
2。在构建项目中使用分类器site 定义所有模块的依赖关系
<!-- Yes, also for the parent project. However, not for the build project itself -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>my-project</artifactId>
<version>${project.version}</version>
<classifier>site</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>my-project</artifactId>
<version>${project.version}</version>
<classifier>site</version>
</dependency>
...
3。在程序集描述符中定义dependencySets。通过将子模块站点内容移动到主模块站点目录的相应子目录来修复损坏的链接。
这个想法是使用由于site-classifier 依赖关系而生成的站点jar 工件并解压缩它们。模块链接是相对的,因此将内容解压缩到由其 artifactIds 命名的子目录中将修复这些链接。
<dependencySets>
<dependencySet>
<outputDirectory>site</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
<includes>
<include>*:my-project:jar:site</include>
</includes>
</dependencySet>
<!-- sites of sub modules -->
<dependencySet>
<includes>
<include>*:my-child-project-1:jar:site</include>
<include>*:my-child-project-2:jar:site</include>
<include>*:my-project-build:jar:site</include>
</includes>
<outputDirectory>site/${artifact.artifactId}</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
</dependencySet>
<!-- sites of sub-sub modules (if required) -->
<dependencySet>
<includes>
...
</includes>
<outputDirectory>site/${artifact.parent.artifactId}/${artifact.artifactId}</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
</dependencySet>
...
</dependencySets>
4。在根项目中定义site:jar 目标
此目标默认在package 阶段执行并生成“站点”附件(例如my-parent-1.0.0-site.jar),这些附件在步骤 2 中定义为依赖项并在步骤 3 中解包:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
5。运行 mvn package 以生成您的程序集
结果是程序集中的一个子目录“站点”,其中包含带有工作链接的完整站点。