gpt4 book ai didi

java - Intellij IDEA 无法解决 Gradle 依赖关系

转载 作者:太空宇宙 更新时间:2023-11-04 11:06:47 25 4
gpt4 key购买 nike

我正在使用 Intellij IDEA 2017.2.4Gradle 4.0.1我的 Spring Boot 服务很少。我在运行它们时面临一个问题,由于缺少依赖项,它们在以随机方式启动时可能会失败。

我有一个带有 build.gradle 的父项目:

buildscript {
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org/m2/" }
mavenLocal()
}

dependencies {
classpath("io.spring.gradle:dependency-management-plugin:$dependencyManagementPluginVersion")
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}

allprojects {
apply plugin: 'java'
apply plugin: 'idea'

group = '***'
version = '***'
}

subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8

processResources {
filesMatching('**/*.yml') {
expand(project.properties)
}
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {

imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion")
mavenBom("org.springframework.boot:spring-boot-dependencies:$springBootVersion")
}

dependencies {
dependency "com.google.cloud:google-cloud-storage:$googleCloudStorageVersion"
...
dependency "org.junit.jupiter:junit-jupiter-api:$junitVersion"
}
}
}

还有一个子项目build.gradle:

apply plugin: 'org.springframework.boot'

repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
mavenLocal()
}

dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
...
testCompile('com.h2database:h2')
}

在某些情况下,lombok 依赖项会丢失,而在其他 javax 依赖项中。它表明依赖项不存在。

enter image description here

但是在我按刷新所有 Gradle 项目并再次构建后,它就可以工作了。

enter image description here

也许有人遇到了同样的问题并有解决方案?

最佳答案

您似乎对 lombok 依赖性有问题。第一步是确保将 lombok 添加为编译时依赖项,例如:

repositories {
mavenCentral()
}

dependencies {
compileOnly 'org.projectlombok:lombok:1.16.18'
}

第二步是确保您的 Intellij 上安装了最新的 lombok 插件。当您尝试在 IDE 中编译项目时,这一点非常重要。另一件可能有帮助的事情是在 Intellij 配置中设置自动更新依赖项。

关于java - Intellij IDEA 无法解决 Gradle 依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46407571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com