Gradle : Unable to generate QueryDSL classes
Asked Answered
M

1

2

Gradle version: 5.1

Java version: 11

I have the following task defined in gradle file to generate QueryDSL classes:

task generateQClasses (type: JavaCompile) {
    source = sourceSets.main.java.srcDirs
    classpath = sourceSets.main.compileClasspath
    destinationDir = file('src/main/java')
    options.annotationProcessorPath = configurations.annotationProcessor
    options.compilerArgs = ['-proc:only', '-processor', 'com.querydsl.apt.jpa.JPAAnnotationProcessor', '-Aquerydsl.packageSuffix=.querydsl']
}

Below is my dependencies block:

annotationProcessor "com.querydsl:querydsl-apt:4.2.1:jpa"
annotationProcessor "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final"
annotationProcessor "javax.annotation:javax.annotation-api:1.3.2"

If I execute `gradlew generateQClasses, I see the following in the logs:

Attempt to recreate a file for type foo.bar.QClass
error: Attempt to recreate a file for type foo.bar.QClass

It fails with error saying the file already exists. How can I configure this task to overwrite the files if they exist?

Also, the above config is the config for the root project and it has 5 subprojects. AnnotationProcessor is able to overwrite the files in one of the sub project but not the others (all the subprojects have the same config). Am I missing anything?

Minoru answered 11/6, 2020 at 9:12 Comment(5)
Is your goal to move the generated source code out of the build folder, or is it to only generate them when you run your custom task (instead of being part of the normal compile task), or both?Ethos
It's only to generate them when someone executes that task explicitly or when the code is compiled. I do not want to move the generated source code out of the build folder.Minoru
Are you saying you like to have them generated when running compileJava but also generateQClasses? Isn't it easier to just rely on the former, or at least only one of them? Sorry if I am being a bit dense :)Ethos
I only have this task as a separate because it requires different annotationProcessorPath and compilerArgs values compared to compileJava.Minoru
for reference: #54134955Milomilon
U
0

I had the same behavior here... It happens when the generated sources folder isn't empty. Try to execute with gradle clean before. Then will be OK. But I'm trying to replace the default QueryDSL task, with the task that you've done. If I have success, I'll update the answer here.

Unexpected answered 5/11, 2021 at 17:16 Comment(1)
@Darshan Mehta I did some question about it: #69886072.Unexpected

© 2022 - 2024 — McMap. All rights reserved.