Обновите приложение Spring Boot (используя javax.persistence) до JDK 11 - PullRequest
0 голосов
/ 21 января 2019

Я нахожусь в процессе преобразования приложения JDK 8 в JDK 11. Оно создается с использованием Gradle и использует JPA / Hibernate под капотом. Я обновил необходимые модули Gradle, Spring Boot теперь 2.1 и использует оболочку Gradle 5.1. Он использует обработку аннотаций QueryDSL JPA для построения классов Q * из базы данных PostgreSQL.

Следующая задача в скрипте сборки генерирует упомянутые классы:

compileJava {
    doFirst {
        generatedSourcesDir.mkdirs();
    }
    options.compilerArgs += [
            '-s', generatedSourcesDir,
    ]

//    dependsOn generateQueryDSL
}

И закомментированная задача генерации QueryDSL:

task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
    source = sourceSets.main.java
    classpath = configurations.compile + configurations.querydslapt
    options.compilerArgs = [
            "-proc:only",
            "-processor", "com.querydsl.apt.jpa.JPAAnnotationProcessor"
    ]
    destinationDir = generatedSourcesDir
}

Основная ошибка, которую я получаю при выполнении задачи Gradle compileJava, заключается в следующем:

* What went wrong:
Execution failed for task ':app-base:compileJava'.
> java.lang.NoClassDefFoundError: javax/persistence/Entity

Я использую следующую зависимость сборки:

compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.2.1'

Который не обновлялся с прошлого лета. Можно ли как-нибудь заставить задачу JavaCompile Gradle работать с JDK 11 и JPA 2.2?

ОБНОВЛЕНИЕ 2/1/2019 - build.gradle для проекта API по запросу пользователя (работает с JDK 11 и Spring Boot 2.1 и Gradle 4.8, но требует значительной очистки, хотя для Gradle 5)

buildscript {
    repositories {
        jcenter()
        mavenLocal()
        mavenCentral()
        maven { url "http://repo.spring.io/libs-release" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: "jacoco"

jar {
    enabled = true
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "http://repo.spring.io/libs-release" }
}

ext {
    generatedSourcesDir = file("${buildDir}/generated-sources")
    pojogenGeneratedDir = file("src/pojogen")
}

sourceSets {
    main {
        java {
            srcDir "src/main/java"
            srcDir pojogenGeneratedDir
            srcDir generatedSourcesDir
        }
    }
}

configurations {
    provided
    compile.extendsFrom provided
}

compileJava {
    doFirst {
        generatedSourcesDir.mkdirs();
    }
    options.compilerArgs += [
            '-s', generatedSourcesDir,
    ]
}

jar {
    enabled = true
}

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

dependencies {

    /*
        SPRING
     */

    testCompile("org.springframework.boot:spring-boot-starter-test:2.1.2.RELEASE")

    // tag::tomcat[]
    compile("org.springframework.boot:spring-boot-starter-web:2.1.2.RELEASE") {
        exclude module: "spring-boot-starter-jetty:2.1.2.RELEASE"
    }
    compile("org.springframework.boot:spring-boot-starter-tomcat:2.1.2.RELEASE")
    // end::tomcat[]
    // tag::actuator[]
    compile("org.springframework.boot:spring-boot-starter-actuator:2.1.2.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-security:2.1.2.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:2.1.2.RELEASE")
    compile("org.springframework.boot:spring-boot-starter-batch:2.1.2.RELEASE")
    compile("org.springframework.boot:spring-boot-devtools:2.1.2.RELEASE")
    // end::actuator[]

    /*
        APACHE COMMONS
     */

    // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'

    // https://mvnrepository.com/artifact/commons-io/commons-io
    compile group: 'commons-io', name: 'commons-io', version: '2.6'

    /*
        GOOGLE GUAVA
     */

    // https://mvnrepository.com/artifact/com.google.guava/guava
    compile group: 'com.google.guava', name: 'guava', version: '27.0.1-jre'

    /*
        LOGBACK
     */

    // https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
    testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

    /*
        MOCKITO
     */

    // https://mvnrepository.com/artifact/org.mockito/mockito-core
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'

    /*
        JWT
     */

    // https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
    compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'

    /*
        MAIL
     */

    // https://mvnrepository.com/artifact/com.sun.mail/javax.mail
    compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'

    // https://mvnrepository.com/artifact/javax.mail/javax.mail-api
    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'

    /*
        SWAGGER
     */

    // https://mvnrepository.com/artifact/io.springfox/springfox-swagger2
    compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'

    // https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'

    /*
        PASSWORD VALIDATOR
    */

    // https://mvnrepository.com/artifact/org.passay/passay
    compile group: 'org.passay', name: 'passay', version: '1.3.1'

    /*
        LOMBOK
     */

    // https://mvnrepository.com/artifact/org.projectlombok/lombok
    provided group: 'org.projectlombok', name: 'lombok', version: '1.18.4'

    /*
        Thymeleaf
     */

//    // https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf
//    compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.9.RELEASE'
//
//    // https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4
//    compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.9.RELEASE'

    /*
        H2 (unit testing)
     */

    // https://mvnrepository.com/artifact/com.h2database/h2
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'

    /*
        Thumbnail tools
     */

    // https://mvnrepository.com/artifact/net.coobird/thumbnailator
    compile group: 'net.coobird', name: 'thumbnailator', version: '0.4.8'

    /*
        JUNIT
     */

    testCompile("junit:junit")
}

/*
    BUILD EXCLUSIONS
 */

test {
    systemProperties 'property': 'value'
    testLogging {
        events "passed", "skipped", "failed", "standardOut", "standardError"
    }
}

/*
    JaCoCo
 */
jacoco {
    toolVersion = "0.7.6.201602180812"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/jacocoHtml"
    }
}

1 Ответ

0 голосов
/ 21 января 2019

Я заставил его работать с JDK 11, откатив Gradle до 4.8 и откатив зависимости Hibernate.Спросите, если меня интересуют точные зависимости, которые я использую.

...