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

Micronaut gRPC项目Gradle构建失败:无法解析micronaut-gradle-plugin:4.0.2

解决Micronaut gRPC项目构建失败(Java版本不兼容+Gradle插件API版本问题)

问题详情

我按照Micronaut gRPC指南创建应用,配置如下:
配置截图

执行./gradlew build时构建失败,错误信息如下:

% ./gradlew build

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'genz'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve io.micronaut.gradle:micronaut-gradle-plugin:4.0.2.
     Required by:
         project : > io.micronaut.application:io.micronaut.application.gradle.plugin:4.0.2
      > No matching variant of io.micronaut.gradle:micronaut-gradle-plugin:4.0.2 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.2.1' but:
          - Variant 'apiElements' capability io.micronaut.gradle:micronaut-gradle-plugin:4.0.2 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'javadocElements' capability io.micronaut.gradle:micronaut-gradle-plugin:4.0.2 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'runtimeElements' capability io.micronaut.gradle:micronaut-gradle-plugin:4.0.2 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
          - Variant 'sourcesElements' capability io.micronaut.gradle:micronaut-gradle-plugin:4.0.2 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 929ms

核心问题分析

  • Micronaut Gradle插件4.0.2要求Java 17,但当前环境使用Java 11,版本不兼容
  • 同时存在Gradle插件API版本(8.2.1)与插件的匹配问题

解决方案

方案1:升级环境到Java 17(推荐)

  1. 安装Java 17(OpenJDK或Oracle JDK均可)
  2. 配置项目使用Java 17:
    • 在build.gradle中添加或修改:
      java {
          sourceCompatibility = JavaVersion.VERSION_17
          targetCompatibility = JavaVersion.VERSION_17
      }
      
    • 在gradle.properties中设置:
      java.version=17
      
  3. 验证Java版本:执行java -version确认输出为Java 17
  4. 重新执行构建命令:./gradlew build

方案2:降级Micronaut插件版本(需保留Java 11时使用)

Micronaut 3.x系列支持Java 11,修改项目的settings.gradle或build.gradle中的插件版本:

  • 在settings.gradle中修改为3.x兼容版本(例如3.9.4):
    plugins {
        id "io.micronaut.application" version "3.9.4"
    }
    
  • 同步项目后重新执行./gradlew build

补充:Gradle版本匹配

  • Micronaut 4.x推荐搭配Gradle 8.x(当前使用的8.2.1版本兼容,升级Java 17后即可正常使用)
  • Micronaut 3.x兼容Gradle 7.x或8.x,降级插件后可保留当前Gradle版本或调整到对应兼容版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 18:28:39