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

Java Azure Function通过Maven部署后依赖缺失抛出运行异常

问题原因

核心根因

命令行部署时的最终部署包缺失正确版本的reactor-netty依赖,而IntelliJ Azure插件部署时会自动完成依赖的全量打包/版本适配,因此运行正常。具体分为两种常见情况:

  1. 缺失依赖打包配置
    你的pom.xml中未配置maven-shade-plugin或maven-assembly-plugin生成包含所有传递依赖的胖Jar,也没有配置将第三方依赖拷贝到Azure Functions部署要求的lib目录。默认的mvn package仅会编译你项目自身的代码,不会将reactor-netty这类传递依赖打入部署包,而IntelliJ插件在部署阶段会自动扫描所有依赖并拷贝到对应的部署目录中。
  2. 依赖版本冲突
    你引入的多个Azure SDK包传递依赖的reactor-netty版本存在冲突,IntelliJ内置的Maven依赖调解策略和你本地命令行使用的Maven版本调解策略不同,导致IDEA打包时选用了包含HttpClientConfig类的正确版本,命令行打包时选用了版本不匹配的Jar包。

解决步骤

  • 第一步:在pom.xml的<build><plugins>节点下添加maven-shade-plugin配置,打包时自动合并所有依赖:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.4.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
        </execution>
    </executions>
</plugin>
  • 第二步:统一锁定reactor-netty版本,避免冲突,在pom.xml中添加<dependencyManagement>节点固定版本:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty</artifactId>
            <version>1.0.14</version>
        </dependency>
    </dependencies>
</dependencyManagement>
  • 第三步:确认本地命令行使用的Maven版本和IntelliJ中配置的Maven版本一致,避免因Maven版本差异导致的依赖调解结果不同。
  • 验证:执行完mvn clean package后,检查target/azure-functions/${functionAppName}/lib目录下是否存在对应版本的reactor-netty Jar包,存在后再执行mvn azure-functions:deploy即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 11:15:07