6

I am trying to generate the QueryDSL Q classes for my Mongo entities using gradle in a Spring Boot project. The IDE I'm using is Intellij.

The code I'm using is adapted from this topic Generating JPA2 Metamodel from a Gradle build script:

sourceSets {
    generated {
        java {
            srcDirs = ['src/generated/java']
        }
    }
}

configurations {
    querydslapt
}

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", "org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor"
    ]
    destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}

compileJava {
    dependsOn generateQueryDSL
    source  generateQueryDSL.destinationDir
}

compileGeneratedJava {
    dependsOn generateQueryDSL
    options.warnings = false
    classpath += sourceSets.main.runtimeClasspath
}

clean {
    delete sourceSets.generated.java.srcDirs
}

idea {
    module {
        downloadJavadoc = true
        downloadSources = true
        generatedSourceDirs += file('src/generated/java')
    }
}

The problem is that in the end in Intellij I have 3 modules. Main, test and generated. The test and generated modules are dependent on the main module. I would like also for the main module to be dependent on the generated module since I'm using the generated Q classes in my code.

All my attempts to solve this end up in a cyclic dependency error from Gradle.

Can someone give me some tips what I could try to solve this problem.

Thanks!

Community
  • 1
  • 1
Marius
  • 970
  • 1
  • 16
  • 36

0 Answers0