【问题标题】:Maven: Create distribution assembly containing site (multi module)Maven:创建包含站点的分发程序集(多模块)
【发布时间】:2018-04-26 08:52:28
【问题描述】:

我正在使用 maven-assembly-plugin 为我的多模块项目创建一个分发程序集(格式为“dir”)。该项目如下所示:

+ my-project
   +-- my-child-project-1
   +-- my-child-project-2

子项目继承自my-projectmy-project 是一个聚合,即在<modules>-section 中定义子项目。

程序集包含工件、源等。我需要如何设置我的项目以包含该站点?

my-project 站点的子模块链接必须有效。据我所知,这些链接在部署之前不起作用。因此,我想我必须先阶段部署站点(?)。根据docs,只有在创建站点后才能进行登台:

此目标要求站点已经使用站点目标生成,例如通过调用 mvn site。

我怎样才能做到这一点?

有没有办法用一个mvn package 组装所有东西?我的程序集描述必须是什么样的?

【问题讨论】:

    标签: java maven maven-assembly-plugin multi-module maven-site-plugin


    【解决方案1】:

    我不知道,如果这是一个好的解决方案,但没有其他答案,所以我想出了这个:

    1。将程序集构建移动到单独的子模块中

    重要提示:我不知道这是否有必要,但是如果在根项目中配置了程序集,我没有时间检查它是否也有效。否则,您必须在步骤 2 中使用不同的分类器定义 my-projectmy-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 以生成您的程序集

    结果是程序集中的一个子目录“站点”,其中包含带有工作链接的完整站点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      相关资源
      最近更新 更多