Error when adding @Entity tag in my entity class run by Java Gradle Program

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

Error when adding @Entity tag in my entity class run by Java Gradle Program

问题

我目前正在使用Gradle程序,需要我使用2个实体类实现DTO,但是一旦我在其中一个实体类中添加了`@Entity`标签,当我将光标悬停在上面时,它会显示`Cannot resolve symbol Entity`。

**Build.Gradle**

    plugins {
        id 'org.springframework.boot' version '2.3.4.RELEASE'
    }
    
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'
    
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    group 'AbtMainTestControl'
    version '1.0-SNAPSHOT'
    
    // 依赖版本
    wrapper.gradleVersion = '5.5.1'
    def cucumberVersion = '4.7.1'
    def junitVersion = '5.5.0'
    def restVersion = '4.1.2'
    def apacheDrillVersion = '1.17.0'
    
    repositories {
        jcenter()
        mavenCentral()
    }
    
    dependencies {
        implementation 'android.arch.persistence.room:runtime:1.1.1'
        compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
        compile group: 'com.opencsv', name: 'opencsv', version: '4.0'
    
        compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
    
        compile group: 'org.apache.drill.tools', name: 'tools-parent', version: "${apacheDrillVersion}", ext: 'pom'
    
        // Cucumber Pretty Report Plugin
        compile group: 'de.monochromata.cucumber', name: 'reporting-plugin', version: '3.0.9'
        
        testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre8'
    
        compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.7.0'
    
        // 导入 ModelMapper 库用于DTO
        compile 'org.modelmapper:modelmapper:2.3.3'
        
        testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
        testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
        testImplementation "io.rest-assured:rest-assured:${restVersion}"
        testImplementation "io.rest-assured:json-path:${restVersion}"
        testImplementation "io.rest-assured:json-schema-validator:${restVersion}"
    
        testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
        annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
        testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
        testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junitVersion}"
        implementation 'junit:junit:4.12'
    
        // Lombok 插件用于DTO
        compileOnly 'org.projectlombok:lombok:1.18.12'
        annotationProcessor 'org.projectlombok:lombok:1.18.12'
    
        // MapStruct Mapper 框架用于序列化DTO
        implementation 'org.mapstruct:mapstruct:1.4.0.Final'
        annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final'
    
        testCompileOnly 'org.projectlombok:lombok:1.18.12'
        testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
    }
    
    configurations {
        cucumberRuntime {
            extendsFrom testImplementation
        }
    }
    
    task cucumber() {
        dependsOn assemble, compileTestJava
        doLast {
            javaexec {
                main = "io.cucumber.core.cli.Main"
                classpath =  configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
                args = ['--plugin',
                        'pretty',
                        '--glue',
                        'gradle.cucumber',
                        'src/test/resources/features',
                ]
            }
        }
    }
    
    test {
        //useJUnitPlatform()
        systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
    }

有人能告诉我如何解决这个问题吗?

注意:此程序尚未运行,因此没有堆栈跟踪。此外,实体类的实现尚未完成。
英文:

I'm currently using Gradle program which requires me to implement DTO with 2 Entity Classes but as soon as I add the @Entity tag in one of the entity classes, it says Cannot resolve symbol Entity when I hover the cursor onto it.

Build.Gradle

plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
group 'AbtMainTestControl'
version '1.0-SNAPSHOT'
// Versioning of dependencies
wrapper.gradleVersion = '5.5.1'
def cucumberVersion = '4.7.1'
def junitVersion = '5.5.0'
def restVersion = '4.1.2'
def apacheDrillVersion = '1.17.0'
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation 'android.arch.persistence.room:runtime:1.1.1'
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
compile group: 'com.opencsv', name: 'opencsv', version: '4.0'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
// https://mvnrepository.com/artifact/org.apache.drill.tools/tools-parent
compile group: 'org.apache.drill.tools', name: 'tools-parent', version: "${apacheDrillVersion}", ext: 'pom'
// Cucumber Pretty Report Plugin
compile group: 'de.monochromata.cucumber', name: 'reporting-plugin', version: '3.0.9'
testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre8'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.7.0'
// Importing ModelMapper Library for DTO
compile 'org.modelmapper:modelmapper:2.3.3'
testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
testImplementation "io.rest-assured:rest-assured:${restVersion}"
testImplementation "io.rest-assured:json-path:${restVersion}"
testImplementation "io.rest-assured:json-schema-validator:${restVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junitVersion}"
implementation 'junit:junit:4.12'
//Lombok plugin for DTO
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
//MapStruct Mapper Framework for serialising DTO
implementation 'org.mapstruct:mapstruct:1.4.0.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
task cucumber() {
dependsOn assemble, compileTestJava
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath =  configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--plugin',
'pretty',
'--glue',
'gradle.cucumber',
'src/test/resources/features',
]
}
}
}
test {
//useJUnitPlatform()
systemProperty "cucumber.options", System.properties.getProperty("cucumber.options")
}

Can someone enlighten me on how to resolve this issue?

Note: This program hasn't been run yet so no StackTrace. Moreover, the implementation of entity classes is not yet completed.

答案1

得分: 2

你还没有导入 Spring 的依赖。你需要按照 文档 中所示的方式手动进行导入:

dependencies {
	implementation('org.springframework.boot:spring-boot-starter-web')
	implementation('org.springframework.boot:spring-boot-starter-data-jpa')
}
英文:

You haven't imported the spring dependencies yet. You need to do that manually, as is shown in the documentation:

dependencies {
	implementation('org.springframework.boot:spring-boot-starter-web')
	implementation('org.springframework.boot:spring-boot-starter-data-jpa')
}

huangapple
  • 本文由 发表于 2020年10月14日 16:07:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/64349118.html
匿名

发表评论

匿名网友

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

确定