Maven:是否可以为多个配置文件指定同一插件的不同版本,同时激活所有这些配置文件?

Maven: is it possible to specify a different version of a same plugin for multiple profiles, while activating all those profiles at the same time?

我有一个 Maven 项目,我在其中使用 Swagger 创建了一些 API 定义。使用 openapi-generator-maven-plugin,我生成了 JAVA 代码和 TypeScript 代码以使用 API。

在我的 pom.xml 配置中,我为每种语言定义了一个 Maven 配置文件。问题是我想在生成 JAVA 代码时使用该插件的 4.2.0 版,在生成 TypeScript 代码时使用 4.3.0 版:我在两个配置文件中都使用了 4.2.0 版,但一些新功能出现在用于 TypeScript 生成的版本 4.3.0,经过一些测试后,我认为我想为 JAVA 生成避免一些副作用。

当每个配置文件单独激活时,一切都按预期工作。 但是如果我激活这两个配置文件,Maven 使用的是最新版本的插件:4.3.0.

由于我的 Maven 项目将在 CI/CD 服务器中构建,我想知道是否可以在单个构建期间基于配置文件使用同一 Maven 插件的特定版本,或者我是否可以需要为每个配置文件创建一个单独的版本?

我的 pom.xml 看起来像这样:

<profiles>
    <profile>
        <id>java</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.openapitools</groupId>
                    <artifactId>openapi-generator-maven-plugin</artifactId>
                    <version>4.2.0</version>
                    <executions>
                        <execution>
                            <id>generate-api-java-model</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <phase>generate-sources</phase>
                            <configuration>
                                ...
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>typescript</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.openapitools</groupId>
                    <artifactId>openapi-generator-maven-plugin</artifactId>
                    <version>4.3.0</version>
                    <executions>
                        <execution>
                            <id>generate-api-ts-model</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <phase>generate-sources</phase>
                            <configuration>
                              ...
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

不可以,每个版本只能有一个插件版本。