Intellij Idea “用MySQL访问数据”Spring指南是开箱即用的?

bzzcjhmw  于 2023-05-06  发布在  Mysql
关注(0)|答案(1)|浏览(133)

参考https://spring.io/guides/gs/accessing-data-mysql/上的教程/指南,我下载了gs-accessing-data-mysql-main.zip
该ZIP文件在以下子文件夹中包含两个项目:

  • 初始(空)
  • complete(完成,每个教程,准备构建和运行)

使用最新的IntelliJ IDEA 2023.1.1,我打开了complete项目。它至少应该没有错误地构建,但是,相反,它发出了一连串的错误消息,我不知道如何修复它们:

A problem occurred configuring root project 'accessing-data-mysql'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.0.0.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.0.0
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.4.2' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.4.2')
          - Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.4.2')
          - Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0 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.4.2')
          - Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.0.0 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.4.2')
          - Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.4.2')
          - Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.0.0 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.4.2')

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

如果您下载gs-accessing-data-mysql-main.zip并重复我概述的几个步骤,您可以很容易地重现这个问题。
在同一个Build窗口中,在上述消息的下面,有一个对应的堆栈跟踪(太长,无法放入帖子)。
注意:我验证了项目是否正确设置为Java 17

我有两个问题:
1.问题的根本原因是什么?
1.我该怎么解决这个问题?

t2a7ltrp

t2a7ltrp1#

我找到了根本原因并修复了它。为了其他人的利益(他们可能像我一样追逐自己的尾巴),我在这里发布我的发现。
1.根本原因是“Gradle构建系统”使用环境JAVA_HOME(Java 8),而不是使用我在IntelliJ的Project StructureProject SettingsModule(Java 17)中配置的内容-尽管在IDE下运行。
1.修复方法是在IntelliJ设置中的另一个位置设置Java 17:FileSettingsBuild, Execution, DeploymentGradle

为了避免像我一样浪费宝贵的时间,在开发系统中安装一个且唯一的JDK/JRE版本是很好的。然而,当同时处理不同的项目和使用不同的工具(需要不同版本的Java)时,这并不总是可能的。
下面的命令可以帮助确定哪些java/javac安装在Windows开发环境中:

C:\>dir /s /n /b java.exe
C:\>dir /s /n /b javac.exe

相关问题