【问题标题】: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:是否可以为多个配置文件指定同一插件的不同版本,同时激活所有这些配置文件?
【发布时间】:2020-04-21 15:40:57
【问题描述】:

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

在我的pom.xml 配置中,我为每种语言定义了一个 Maven 配置文件。问题是我想在生成 JAVA 代码时使用该插件的 4.2.0 版本,在生成 TypeScript 代码时使用 4.3.0 版本:我在两个配置文件中都使用 4.2.0 版本,但在 4.3.0 版本中出现了一些新功能对于 TypeScript 生成,经过一些测试,我想在生成 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>

【问题讨论】:

  • 问题是为什么您认为有必要...在一个构建中激活不同的版本?
  • 该插件的维护者在 4.3.0 版本中添加了一些特定于 TypeScript 的新配置属性。但与此同时,它们引入了一些可能被视为对其他语言的副作用的小改动

标签: maven maven-3


【解决方案1】:

不,每个构建只能有一个插件版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 2011-06-05
    相关资源
    最近更新 更多