首页 > 解决方案 > 使用 bootRun generate 运行时 Gradle 找不到符号 isEmpty

问题描述

我正在使用 Gradle 编译项目,当我使用 bootRun 运行它时,它输出以下错误:找不到符号 isEmpty,其中很多,我知道这是 java 版本的问题,但我不知道如何为了纠正他们,很遗憾他们不允许发布短版。

这是我的gradle配置:

    buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
plugins {
    id 'org.springframework.boot' version '2.2.0.M5'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
    id 'net.ltgt.apt' version '0.20'
}

apply plugin: 'net.ltgt.apt-idea'
apply plugin: 'kotlin'
apply plugin: 'net.ltgt.apt-eclipse'

group = 'com.fanjiu'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    mapstruct
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
}

ext {
    set('springCloudVersion', "Hoxton.M2")
    generatedMapperSourcesDir = "${buildDir}/generated-src/mapstruct/main"
}

sourceSets.main {
    ext.originalJavaSrcDirs = java.srcDirs
    java.srcDir "${generatedMapperSourcesDir}"
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-batch'
    implementation 'org.springframework.boot:spring-boot-starter-cloud-connectors'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation('com.github.binarywang:wx-java-miniapp-spring-boot-starter:3.5.0')
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile('org.modelmapper:modelmapper:2.3.5')
    implementation 'org.springframework.cloud:spring-cloud-starter'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }


    implementation "org.mapstruct:mapstruct"
    annotationProcessor "org.mapstruct:mapstruct-processor"

    compileOnly 'org.projectlombok:lombok:1.18.10'
    annotationProcessor 'org.projectlombok:lombok:1.18.10'
    compile 'org.mapstruct:mapstruct:1.3.0.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Final'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile 'com.qiniu:qiniu-java-sdk:7.2.+'
    compile 'com.alibaba:fastjson:1.2.61'
    compile group: 'org.ocpsoft.prettytime', name: 'prettytime', version: '4.0.2.Final'
    compile group: 'org.ocpsoft.prettytime', name: 'prettytime-nlp', version: '4.0.2.Final'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

test {
    useJUnitPlatform()
}



task generateMainMapperClasses(type: JavaCompile) {
    ext.aptDumpDir = file( "${buildDir}/tmp/apt/mapstruct" )
    destinationDir = ext.aptDumpDir

    classpath = compileJava.classpath + configurations.mapstruct
    source = sourceSets.main.originalJavaSrcDirs
    ext.sourceDestDir = file ( "$generatedMapperSourcesDir" )

    options.define(
            compilerArgs: [
                    "-nowarn",
                    "-proc:only",
                    "-encoding", "UTF-8",
                    "-processor", "org.mapstruct.ap.MappingProcessor",
                    "-s", ext.sourceDestDir.absolutePath,
                    "-source", rootProject.sourceCompatibility,
                    "-target", rootProject.sourceCompatibility,
            ]
    );

    inputs.dir source
    outputs.dir generatedMapperSourcesDir;
    doFirst {
        ext.sourceDestDir.mkdirs()
    }
    doLast {
        ext.aptDumpDir.delete()
    }
}
compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

//compileJava.dependsOn generateMainMapperClasses

标签: javagradle

解决方案


是的。JDK版本,升级JDK版本解决问题。并使用 sourceCompatibility = '13' 更新文件


推荐阅读