eclipse 在STS 4中自动添加生成的源文件?

brgchamk  于 2022-11-04  发布在  Eclipse
关注(0)|答案(1)|浏览(164)

目前,我坚持在编译后自动添加构建的源文件。
QueryDSL正在工作(刷新后自动添加。)。但是,MapStruct不工作。
QueryDSL输出是每个项目的src/main/generated/querydsl。MapStruct是其项目上的默认值(build/generated/sources/annotationProcessor/java/main)。
手动添加源文件后,这段代码是工作,但我想自动添加源像querydsl.
这是我的部分build. gradle。
//根构建.gradle

buildscript {
    ext {
        springBootVersion = '2.7.2'
        dependencyManagementVersion = '1.0.12.RELEASE'
        mysqlVersion = '8.0.30'
        lombokVersion = '6.5.0.3'
        queryDslVersion = '4.4.0'
        queryDslPluginVersion = '1.0.10'
        mapStructVersion = '1.5.3.Final'
        lombokMapstructBindingVersion = "0.2.0"
    }
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
        classpath "io.freefair.gradle:lombok-plugin:${lombokVersion}"
        // for QueryDSL
        classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:${queryDslPluginVersion}"
    }
}

subprojects {
    group = 'test.test'
    version '0.0.1-SNAPSHOT'

    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'io.freefair.lombok'
    apply plugin: 'com.ewerk.gradle.plugins.querydsl'

    sourceCompatibility = '11'

    repositories {
        mavenCentral()
    }

    dependencies {
      compile group: 'com.querydsl', name: 'querydsl-jpa'
      annotationProcessor group: 'com.querydsl', name: 'querydsl-apt'

        // for QueryDSL
        // implementation "com.querydsl:querydsl-core:${queryDslVersion}"
        // implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
        // annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa"
        annotationProcessor "jakarta.persistence:jakarta.persistence-api"
        annotationProcessor "jakarta.annotation:jakarta.annotation-api"

        annotationProcessor "org.mapstruct:mapstruct-processor:${mapStructVersion}"
        implementation "org.mapstruct:mapstruct:${mapStructVersion}"

        annotationProcessor "org.projectlombok:lombok-mapstruct-binding:${lombokMapstructBindingVersion}"

        testImplementation 'junit:junit:4.12'
    }
}

// for QueryDSL
task cleanGeneatedDir(type: Delete) {
    delete file('src/main/generated')
}

// A项目build.gradle

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
    implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'
    implementation 'com.querydsl:querydsl-jpa:4.4.0'

    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
}

def querydslDir = "src/main/generated/querydsl"

querydsl {
    library = "com.querydsl:querydsl-apt"
    jpa = true
    querydslSourcesDir = querydslDir
}
sourceSets {
    main.java.srcDir querydslDir
}
compileQuerydsl{
    options.annotationProcessorPath = configurations.querydsl
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    querydsl.extendsFrom compileClasspath
}
doinxwow

doinxwow1#

它通过gradle中的sourceSets〉main〉java〉srcDirs自动配置。
在代码中,

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'build/generated/sources/annotationProcessor/java/main']
        }
    }
}

相关问题