为什么IntelliJ IDEA不能解析Maven属性?

huangapple go评论113阅读模式
英文:

Why isn't IntelliJ IDEA resolving maven properties?

问题

我正在运行 Windows 10 64 位操作系统上的 IntelliJ IDEA 2019.3 社区版。它已正确导入和解析了一些依赖项,如 spring-boot、MySQL 连接器 Java 等等。然而,当我尝试添加新的 hibernate-core 依赖并导入更改时,它显示 "无法解析依赖项 hibernate core"。

以下是您提供的 "Pom.xml" 部分:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.5.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.resondate</groupId>
	<artifactId>resondate</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>resondate</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<!-- 其他依赖项已省略 -->

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>6.0.0.Alpha4</version>
			<type>pom</type>
		</dependency>
	</dependencies>
	<!-- 其他部分已省略 -->
</project>

出现的错误消息如下:

无法解析 org.hibernate:hibernate-core:6.0.0.Alpha4

对于所有版本的 hibernate-core 都出现了此错误。请提供关于为何会发生这种情况的见解。谢谢。

英文:

I'm running IntelliJ IDEA 2019.3 community edition on windows 10 64-bit. It correctly imported and resolved few dependencies like spring-boot, MySQL connector Java, etc.,. However, when I try to add a new dependency for hibernate-core and import changes, it says "Cannot resolve dependency hibernate core".

The "Pom.xml":

 &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;parent&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
		&lt;version&gt;2.2.5.RELEASE&lt;/version&gt;
		&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
	&lt;/parent&gt;
	&lt;groupId&gt;com.resondate&lt;/groupId&gt;
	&lt;artifactId&gt;resondate&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;name&gt;resondate&lt;/name&gt;
	&lt;description&gt;Demo project for Spring Boot&lt;/description&gt;

	&lt;properties&gt;
		&lt;java.version&gt;1.8&lt;/java.version&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
					&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
			&lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
			&lt;artifactId&gt;lombok&lt;/artifactId&gt;
			&lt;version&gt;1.18.10&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
			&lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
			&lt;version&gt;2.10.0&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.liquibase&lt;/groupId&gt;
			&lt;artifactId&gt;liquibase-core&lt;/artifactId&gt;
			&lt;version&gt;3.8.4&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
			&lt;version&gt;8.0.14&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
			&lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
			&lt;version&gt;6.0.0.Alpha4&lt;/version&gt;
			&lt;type&gt;pom&lt;/type&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.liquibase&lt;/groupId&gt;
				&lt;artifactId&gt;liquibase-maven-plugin&lt;/artifactId&gt;
				&lt;configuration&gt;
					&lt;propertyFile&gt;src/main/resources/liquibase.properties&lt;/propertyFile&gt;
				&lt;/configuration&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;phase&gt;process-resources&lt;/phase&gt;
						&lt;goals&gt;
							&lt;goal&gt;update&lt;/goal&gt;
						&lt;/goals&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

&lt;/project&gt;

The error message that comes up is as follows:

> Cannot resolve org.hibernate:hibernate-core:6.0.0.Alpha4

It does this for all versions of hibernate-core. Please provide insights as to why this is happening. Thank you.

答案1

得分: 0

  1. 不要使用 Hibernate 的 Alpha 版本。
  2. 如果你无法抵制,而不是覆盖整个依赖块,只需指定你想要的版本。多亏了 Spring Boot 的父 POM,这将无缝地运行。示例:

而不是:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>6.0.0.Alpha4</version>
    <type>pom</type>
</dependency>

做:

<properties>
    <hibernate.version>5.4.13.Final</hibernate.version>
</properties>

对于所有其他依赖也是如此,比如 mysql 等。
3. 将版本覆盖为 6.0.0.Alpha 对于 Hibernate 来说不起作用,因为实际的 groupId 已经更改为 org.hibernate.orm。因此,我不会这样做 :)。

英文:
  1. Don't use Hibernate's Alpha version.
  2. If you cannot resist, instead of overriding the whole dependency block, just specify the version you want. Thanks to Spring Boot's parent pom this will work flawlessly. Example:

Instead of:

     &lt;dependency&gt;
        &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
        &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
        &lt;version&gt;6.0.0.Alpha4&lt;/version&gt;
        &lt;type&gt;pom&lt;/type&gt;
    &lt;/dependency&gt;

Do:

&lt;properties&gt;
    &lt;hibernate.version&gt;5.4.13.Final&lt;/hibernate.version&gt;
&lt;/properties&gt;

Same for all other dependencies, like mysql etc.

  1. The version override to 6.0.0.Alpha won't work for Hibernate, as the actual groupId has changed, to org.hibernate.orm . Hence, I wouldn't do it 为什么IntelliJ IDEA不能解析Maven属性?

.

huangapple
  • 本文由 发表于 2020年4月4日 18:47:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/61026949.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定