Intellij IDE not see generated classes in gradle p

2019-08-28 03:07发布

问题:

I have this gradle config:

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

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

group 'mygroup'
version '0.0.1-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
...
}

bootJar {
    mainClassName = 'mypakeg.Application'
    archiveName = 'my-server.jar'
}

sourceSets.configureEach { sourceSet ->
    tasks.named(sourceSet.compileJavaTaskName).configure {
        options.annotationProcessorGeneratedSourcesDirectory = file("$projectDir/generated/sources/java")
    }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation ('org.hibernate:hibernate-jpamodelgen')
    annotationProcessor ('org.hibernate:hibernate-jpamodelgen')
    implementation('org.projectlombok:lombok')
    annotationProcessor 'org.projectlombok:lombok'
}

After build I have folder generated/sources/java with generated files. But Intellij IDE not see this classes. I try click rigth button and marck this folder as root generated classes. But It not helpet becaus:

I have separated module my_server and my_server_main and all classes generated in my_server but my code in my_server_main and if I add dependency to my_server_main I have circular dependency.

How can I generate classes and set path to them?