【问题标题】:Spring boot not adding spring-boot-starter-data-jpaSpring Boot 未添加 spring-boot-starter-data-jpa
【发布时间】:2021-02-09 11:06:56
【问题描述】:

当试图通过 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()
}

在任何人提及之前,是的,我已经多次尝试清理和重建项目。

【问题讨论】:

  • 请将您的答案“SOLVED”添加为答案而不是编辑问题,然后将其从问题中删除并将此评论标记为不再需要。

标签: java spring spring-boot spring-boot-gradle-plugin


【解决方案1】:

按照之前的建议,在 VS Code 清理 Java 项目中帮助我解决了这个问题: 打开“Java项目”视图->“...”->“清理工作区”

根据 VS Code 配置,清理后,gradle 会自动重建依赖项。如果没有,您可以右键单击 build.gradle 并选择“更新项目”

【讨论】:

    【解决方案2】:

    已解决:问题出在 Spring 工具套件中,使用 Project->Clean 没有更新 gradle 依赖项。必须右键单击 build.gradle->gradle->刷新 gradle 项目以更新所有内容。

    【讨论】:

      【解决方案3】:

      如果您使用的是 Gradle 6.x,则 compile 配置已被弃用。从 Gradle 3.4 开始不鼓励使用它。您应该改用implementation。此更改还将使此依赖项与您的构建脚本中的其他依赖项更加一致。您可以在Gradle documentation 中了解更多信息。

      您还为 spring-boot-starter-data-jpa 依赖项指定了一个版本。这不是必需的,因为版本可以由您应用的 Spring Boot 插件的版本确定。这就是脚本中未声明版本的其他依赖项所发生的情况。它使保持所有版本同步变得更加容易。

      简而言之,尝试将依赖声明更新为如下所示:

      implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
      

      【讨论】:

      猜你喜欢
      • 2021-01-18
      • 2015-12-28
      • 2021-11-11
      • 2017-11-29
      • 2018-08-06
      • 2019-06-16
      • 2019-06-16
      • 2018-03-01
      • 2017-03-19
      相关资源
      最近更新 更多