vscode找不到具有main方法的类(关于gradle / springboot)

jucafojl  于 2023-03-23  发布在  Vscode
关注(0)|答案(1)|浏览(863)

我和一个朋友在vscode上合作,但是我朋友的spring工作得很好,但是我的不行。总共有两个错误。
我尝试了各种措施,如gradle插件和java版本,但它不起作用。作为参考,java版本为17.0.5,适用于mac和vscode。感谢观看。

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.6.1-bin.zip'.
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'rezume_project'.
A problem occurred configuring root project 'rezume_project'.
Could not resolve all files for configuration ':classpath'.
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.4.
Required by:
    project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.4
No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.4 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.6.1' but:
  - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.4 declares a library, packaged as a jar, and its dependencies declared externally:
      - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 8
      - Other compatible attribute:
          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.4 declares a runtime of a component, 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 8)
          - Doesn't say anything about its elements (required them packaged as a jar)
          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.4 declares a library, packaged as a jar, and its dependencies declared externally:
      - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 8
      - Other compatible attribute:
          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.4 declares a runtime of a library, 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 8
      - Other compatible attribute:
          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.4 declares a runtime of a library, 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 8
      - Other compatible attribute:
          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
  - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.4 declares a runtime of a component, 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 8)
          - Doesn't say anything about its elements (required them packaged as a jar)
          - Doesn't say anything about org.gradle.plugin.api-version (required '7.6.1')
goqiplq2

goqiplq21#

这条线
找不到org.springframework. Boot :spring-boot-gradle-plugin:3.0.4的匹配变体。消费者被配置为查找与Java 8兼容的库的运行时,打包为jar,其依赖项在外部声明,以及值为“7.6.1”的属性“org.gradle.plugin.api-version”,但是:
声明您的项目需要与Java 8兼容的库。但是,

  • Variant 'runtimeElements' capability org.springframework. Boot :spring-boot-gradle-plugin:3.0.4声明了一个库的运行时,打包为jar,其依赖关系对外声明:- 不兼容,因为此组件声明了与Java 17兼容的组件,而使用者需要与Java 8兼容的组件

说它所能找到的是一个需要Java 17的库,这是正确的,因为Sping Boot 3需要Java 17。
因此,您的本地构建以某种方式运行在Java 8上或以Java 8作为目标配置。您应该通过运行java -version来检查您的shell是否运行Java 17或更高版本。这同样适用于您的IDE配置。

相关问题