You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不同Maven插件间传递Base64编码凭证失败求助

问题分析与修复方案

你的配置未生效主要有以下几个核心问题,对应修复如下:


1. Properties文件格式不匹配(最关键)

properties-maven-plugin的read-project-properties目标要求读取的文件是key=value格式的属性文件,但你用exec-maven-plugin生成的base64-output.txt只有纯Base64字符串,没有对应的键名。这导致插件无法识别并生成${base64-output}属性,自然无法传递给OpenAPI Generator。

修复:修改exec命令生成key=value格式的输出

调整exec-maven-plugin的命令,直接输出base64-output=xxx格式内容:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>compute-base64</id>
            <phase>initialize</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>sh</executable>
                <arguments>
                    <argument>-c</argument>
                    <argument>
                        echo -n "base64-output=$(echo -n '${ar.user}:${ar.password}' | base64)"
                    </argument>
                </arguments>
                <outputFile>${project.build.directory}/base64-output.txt</outputFile>
            </configuration>
        </execution>
    </executions>
</plugin>

2. 插件执行阶段顺序错误

你未指定properties-maven-plugin的执行阶段,默认阶段可能晚于OpenAPI Generator的generate阶段(generate-sources),导致读取属性文件的操作在生成代码之后执行,属性自然无法生效。

修复:指定properties插件的执行阶段为process-resources(在generate-sources之前)

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>read-base64-property</id>
            <phase>process-resources</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${project.build.directory}/base64-output.txt</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

3. OpenAPI Generator的auth参数格式验证

OpenAPI Generator的auth参数要求格式为Basic <base64-string>,而非完整的Authorization: Basic <base64-string>(完整头格式适用于headerParameters参数)。

修复:调整auth参数格式

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>7.2.0</version>
    <configuration>
        <!-- 其他配置保持不变 -->
        <auth>Basic ${base64-output}</auth>
        <!-- 其他配置保持不变 -->
    </configuration>
    <executions>
        <execution>
            <id>generate-api</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

额外验证步骤

  1. 运行mvn initialize后,检查target/base64-output.txt内容是否为base64-output=xxx格式,且xxx是正确的Base64编码字符串。
  2. 运行mvn process-resources后,执行mvn help:describe -Dproperty=base64-output,确认能输出对应的属性值。
  3. 最后运行mvn generate-sources验证OpenAPI Generator是否正常获取认证信息。

内容的提问来源于stack exchange,提问作者sonia belhadj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 00:34:51