2.3. 使用多个模块运行 Maven 插件

要在带有多个模块的项目中使用 Maven 插件,请将配置放在父的 pom.xml 中。在执行 Maven 插件期间,将生成单个报告,其中包含父模块和任何子模块的分析。

注意

强烈建议在多模块项目 中继承 为 false;否则,当每个子编译时,将执行 Maven 插件,从而导致对子模块进行多个 Maven 插件执行。将 inherited 设置为 false 时,每个项目中都分析一次,并大大减少了启动时间。

若要在带有多个模块的项目中运行 Maven 插件,请执行以下步骤:

  1. 在父项目的 pom.xml 中包含以下插件。以下是父模块的 pom.xml 示例。

    <plugin>
        <groupId>org.jboss.windup.plugin</groupId>
        <artifactId>windup-maven-plugin</artifactId>
        <version>4.2.1.Final</version>
        <inherited>false</inherited>
        <executions>
            <execution>
                <id>run-windup</id>
                <phase>package</phase>
                <goals>
                    <goal>windup</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <input>${project.basedir}</input>
            <offlineMode>true</offlineMode>
            <windupHome>/PATH/TO/CLI/</windupHome>
        </configuration>
    </plugin>

    这个 pom.xml 与通过 以下属性运行 Maven 插件时的名称:

    • inherited :在插件级别上定义,此属性指示是否应在子模块中使用此配置。设置为 false 以提高性能。
    • input :指定包含要分析的项目的目录的路径。此属性默认为 {project.basedir}/src/main,并且应该定义父项目没有要分析的源代码。
    • windupHome :MTA CLI 的提取副本的路径。此属性为可选,但建议以提高性能。

      上面的示例演示了一组推荐的参数。有关所有可用 参数的详情,请参阅 MTA Maven 参数。

  2. 构建父项目。在构建过程中,Maven 插件将针对项目中的所有子项执行,而不进行进一步配置。

    $ mvn clean install
  3. 完成后,以正常方式 访问生成的报告。此报告包含父项和所有子项的分析。