当尝试通过gradle将spring-boot-starter-data-jpa添加到我的项目中时,它就是做不到。@Entity标记不起作用,jar不会出现在项目和外部依赖项文件夹中。除非我放入@Entity标记,否则不会出现错误。这是我的gradle文件以供参考。
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.Hype'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:
'2.3.4.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.session:spring-session-jdbc'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}在任何人提到它之前,是的,我已经尝试过多次清理和重建项目。
发布于 2020-10-27 15:48:26
如果您使用的是Gradle6.x,则compile配置已被弃用。从Gradle 3.4开始就不鼓励使用它了。您应该改用implementation。此更改还会使此依赖项与构建脚本中的其他依赖项更一致。您可以在Gradle documentation中了解更多有关这方面的信息。
您还指定了spring-boot-starter-data-jpa依赖项的版本。这不是必需的,因为版本可以由您所应用的Spring Boot插件的版本来确定。这就是脚本中没有声明版本的其他依赖项所发生的情况。这使得保持所有版本的同步变得更容易。
简而言之,尝试更新依赖声明,如下所示:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'发布于 2020-10-28 22:34:46
解决方法:这个问题出现在Spring工具套件中,使用Project->Clean无法更新gradle依赖项。我不得不右击build.gradle-> gradle ->刷新gradle项目来获得所有的更新。
发布于 2021-10-01 21:33:20
遵循前面的建议,在VS Code cleaning Java项目中帮助我解决了这个问题:打开"Java Project“查看-> "...”-> "Clean Workspace“
根据VS代码配置,在清理之后,gradle会自动重建依赖项。如果没有,你可以右击build.gradle并选择“更新项目”。
https://stackoverflow.com/questions/64549884
复制相似问题