如何配置MOM-archetype-plugin不会处理父模块的POM?

时间:2019-07-13 06:39:44

标签: maven maven-plugin

在多模块项目中,很少有工件可以作为原型构建。但是,出于某些原因从根maven-archetype-plugin构建时,会为所有工件初始化派生。这种行为会大大减慢构建速度。我希望只为子模块创建原型,而无需遍历所有项目模块。

此处是父POM配置:

<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app-parent</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <archetype.phase>none</archetype.phase>
    </properties>

    <modules>
        <module>my-app-module1</module>
        <module>my-app-module2</module>
        <module>my-app-module3</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-archetype-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>archetype-generate-project</id>
                        <phase>${archetype.phase}</phase>
                        <goals>
                            <goal>create-from-project</goal>
                        </goals>
                        <configuration>
                            <packageName>${project.groupId}</packageName>
                            <archetypePostPhase>package</archetypePostPhase>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

子模块“ my-app-module1” POM(模块2和模块3相同,只是artifactId不同)

<project>
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.mycompany.app</groupId>
        <artifactId>my-app-parent</artifactId>
        <version>0.1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <archetype.phase>package</archetype.phase>
    </properties>

    <artifactId>my-app-module1</artifactId>

</project>

带有调试标志的构建日志表示对于整个项目模块的每个原型构建,都将初始化派生。这种日志片段乘以项目中原型模块的数量。

[DEBUG] --- init fork of com.mycompany.app:my-app-parent:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): []
[DEBUG] --- exit fork of com.mycompany.app:my-app-parent:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] --- init fork of com.mycompany.app:my-app-module1:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): []
[DEBUG] --- exit fork of com.mycompany.app:my-app-module1:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] --- init fork of com.mycompany.app:my-app-module2:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): []
[DEBUG] --- exit fork of com.mycompany.app:my-app-module2:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] --- init fork of com.mycompany.app:my-app-module3:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): []
[DEBUG] --- exit fork of com.mycompany.app:my-app-module3:0.1.0-SNAPSHOT for org.apache.maven.plugins:maven-archetype-plugin:3.0.1:create-from-project (archetype-generate-project) ---

此处原型的生成与不生成由相位属性archetype.phase控制。

在本地计算机上,构建和不构建原型的时间截然不同。

总时间:用mvn clean install的13.108秒

总时间:使用mvn clean install -Darchetype.phase=none时为2.734秒

0 个答案:

没有答案