问题描述
我有root配置gradle.build
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'idea'
}
idea {
project {
languageLevel = 14
}
module {
downloadJavadoc = true
downloadSources = true
}
}
allprojects {
group "ru.otus"
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
apply plugin: "io.spring.dependency-management"
dependencyManagement {
dependencies {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.3.5.RELEASE")
}
dependency("org.projectlombok:lombok:1.18.16")
dependency("org.springframework.shell:spring-shell-starter:2.0.1.RELEASE")
dependency("org.springframework.boot:spring-boot-starter-data-jpa:2.3.5.RELEASE")
dependency("org.flywaydb:flyway-core:6.4.4")
dependency("org.postgresql:postgresql:42.2.16")
dependency("org.hamcrest:hamcrest-core:1.3")
dependency("org.springframework.boot:spring-boot-starter-test:2.3.5.RELEASE")
}
}
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
resolutionStrategy {
force("javax.servlet:servlet-api:2.4")
force("commons-logging:commons-logging:1.1.1")
force("commons-lang:commons-lang:2.5")
force("org.codehaus.jackson:jackson-core-asl:1.8.8")
force("org.codehaus.jackson:jackson-mapper-asl:1.8.3")
force("org.codehaus.jettison:jettison:1.1")
force("org.javassist:javassist:3.24.0-GA")
force("org.apiguardian:apiguardian-api:1.1.0")
force("org.opentest4j:opentest4j:1.2.0")
}
}
}
并在模块中有build.gradle
plugins {
id 'java'
}
version = '0.0.1-SNAPSHOT'
dependencies {
implementation group: 'org.springframework.shell',name: 'spring-shell-starter',version: '2.0.1.RELEASE'
implementation group: 'org.springframework.boot',name: 'spring-boot-starter',version: '2.3.5.RELEASE'
implementation group: 'org.flywaydb',name: 'flyway-core',version: '6.4.4'
testCompile group: 'org.hamcrest',name: 'hamcrest-core',version: '1.3'
testImplementation group: 'org.springframework.boot',name: 'spring-boot-starter-test',version: '2.3.5.RELEASE'
}
下载依赖项并添加模型注解(例如@ Entity,@ Table @Id等)后,我出现了错误:找不到符号 @实体 ^ 符号:类实体 但是我在依赖项中有spring-boot-starter-jpa,我不知道为什么在模块中我不能使用依赖项。
解决方法
使用dependencyManagement
时,您仅管理版本,覆盖等依赖项,而实际上并未将依赖项添加到项目中。为此,请像在其他地方一样使用dependencies
。