Spring Boot没有添加spring-boot-starter-data-jpa。

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

Spring boot not adding spring-boot-starter-data-jpa

问题

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

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

英文:

When trying to add spring-boot-starter-data-jpa to my project through gradle, it just doesn't do it. The @Entity tag doesn't work and the jar doesn't appear in the project and external dependencies folder. There's no error unless I put in the @Entity tag. Here is my gradle file for reference.

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()
}

Before anyone mentions it, yes I've tried cleaning and rebuilding the project multiple times.

答案1

得分: 2

如果您正在使用Gradle 6.x,compile 配置已被弃用。自从 Gradle 3.4 开始,其使用就不被鼓励。您应该使用 implementation 代替。这个变更还会使得您构建脚本中的此依赖与其他依赖更加一致。您可以在Gradle文档中了解更多相关信息。

另外,您已经在 spring-boot-starter-data-jpa 依赖项上指定了一个版本。这并不是必要的,因为版本可以由您应用的Spring Boot插件的版本来确定。这就是在您的脚本中其他依赖项中发生的情况,其中没有声明版本。这可以更轻松地保持所有版本的同步。

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

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

If you are using Gradle 6.x, the compile configuration has been deprecated. Its use has been discouraged since Gradle 3.4. You should use implementation instead. This change would also make this dependency more consistent with the others in your build script. You can learn a bit more about this in the Gradle documentation.

You've also specified a version on the spring-boot-starter-data-jpa dependency. This isn't necessary as the version can be determined by the version of the Spring Boot plugin that you've applied. This is what's happening with the other dependencies in your script where no version is declared. It makes it easier to keep all of the versions in sync.

In short, try updating the dependency declaration to look like the following:

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

答案2

得分: 0

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

英文:

SOLVED: The issue was in Spring tool suite, using Project->Clean wasn't updating gradle dependencies. Had to right click build.gradle->gradle->refresh gradle project to get everything to update.

答案3

得分: 0

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

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

英文:

Following the previous suggestion, in the VS Code cleaning Java project helped me to resolve the issue:
Open "Java Project" view -> "..." -> "Clean Workspace"

Depending on VS Code configuration, after the cleaning, the gradle rebuilds dependencies automatically. If not, you can right-click on build.gradle and select "Update Project"

huangapple
  • 本文由 发表于 2020年10月27日 15:31:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64549884.html
匿名

发表评论

匿名网友

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

确定