Gradle 注释处理器和依赖项

Gradle 注释处理器和依赖项,gradle,querydsl,apt,Gradle,Querydsl,Apt,我正在使用gradle/querydsl和JPA2.1 我想使用APT(QEntities)生成querydsl元数据 为此,我使用了gradle apt插件和gradle 4.7 在我的项目中,我使用以下配置了compileJava选项: compileJava{ options.annotationProcessorGeneratedSourcesDirectory=文件(“$projectDir/src/generated2/java”) } 在我的依赖项中,我添加了 编译“org.s

我正在使用gradle/querydsl和JPA2.1

我想使用APT(QEntities)生成querydsl元数据

为此,我使用了gradle apt插件和gradle 4.7

在我的项目中,我使用以下配置了compileJava选项:

compileJava{
options.annotationProcessorGeneratedSourcesDirectory=文件(“$projectDir/src/generated2/java”)
}

在我的依赖项中,我添加了


编译“org.springframework.boot:springbootstarterdatajpa”
注释处理器“com.querydsl:querydsl apt:$querydsl版本:jpa”

spring初学者将org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final jar添加到compileClasspath中,该jar包含javax.persistence.Entity类

启动compileJava任务时,我遇到错误:
原因:java.lang.NoClassDefFoundError:javax/persistence/Entity位于com.querydsl.apt.jpa.JPAAnnotationProcessor.createConfiguration(JPAAnnotationProcessor.java:37)


我不理解注释处理器为什么不能加载此类。

以防其他人正在搜索。这是我的完整解决方案(基于您的响应)。重要的部分是在eclipse中激活代码生成的
net.ltgt.apt*
插件,以及最后三个querydsl依赖项

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}


plugins { // activates the automatic code generation
    id 'net.ltgt.apt' version '0.18'
    id 'net.ltgt.apt-eclipse' version '0.18' 
}


apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

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

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}


dependencies {
    runtimeOnly             'com.h2database:h2'
    implementation          'org.springframework.boot:spring-boot-starter-actuator'
    implementation          'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation          'org.springframework.boot:spring-boot-starter-web'
    providedRuntime         'org.springframework.boot:spring-boot-starter-tomcat'


    testImplementation      'org.springframework.boot:spring-boot-starter-test'
    testImplementation      'org.springframework.boot:spring-boot-starter-webflux'

    // querydsl
    annotationProcessor     'com.querydsl:querydsl-apt:4.1.3:jpa'
    annotationProcessor     'org.springframework.boot:spring-boot-starter-data-jpa' // needed because the query dsl annotation processor doesn't recognize javax.persistence.Entity
    compile                 'com.querydsl:querydsl-jpa:4.1.3'
}
解决者