Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QClasses are not generated in a multi-module Maven project #3599

Open
simasch opened this issue Sep 28, 2023 · 16 comments
Open

QClasses are not generated in a multi-module Maven project #3599

simasch opened this issue Sep 28, 2023 · 16 comments
Labels

Comments

@simasch
Copy link

simasch commented Sep 28, 2023

I use Spring Boot 3.1.4 and I've configured the dependencies in each module where QueryDSL is used

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>${querydsl.version}</version>
        <classifier>jakarta</classifier>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>${querydsl.version}</version>
        <classifier>jakarta</classifier>
        <scope>provided</scope>
    </dependency>

But no QClasses are generated.

If I use the exact same dependencies in a single module Spring Boot project everything works fine.

Any idea what the difference could be?

@simasch simasch added the bug label Sep 28, 2023
@scordio
Copy link

scordio commented Sep 28, 2023

Not sure if it helps but this is my non-Jakarta setup for Spring Boot 2.7 which works fine on many multi-module projects:

<dependencies>
  ...
  <dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId> <!-- version omitted because of the SB starter parent -->
  </dependency>
  ...
</dependencies>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <annotationProcessorPaths>
          <path>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version> <!-- version required -->
            <classifier>jpa</classifier>
          </path>
          <path>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>${javax-persistence.version}</version>  <!-- version required -->
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>
  </plugins>
</build>

@SebastianDietrich
Copy link

SebastianDietrich commented Sep 28, 2023

Hmm - I have such a multi-module maven project with querydsl.
The most important difference is the following:

<!-- to generate code for querydsl -->
<plugin>
  <groupId>com.mysema.maven</groupId>
  <artifactId>apt-maven-plugin</artifactId>
  <version>${apt-maven-plugin.version}</version>
  <executions>
    <execution>
      <goals>
        <goal>process</goal>
      </goals>
      <configuration>
        <outputDirectory>target/generated-sources/java</outputDirectory>
        <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
      </configuration>
    </execution>
  </executions>
</plugin>

@simasch
Copy link
Author

simasch commented Sep 28, 2023

@SebastianDietrich The Maven Plugin is no longer necessary.
@scordio, unfortunately, this didn't help and shouldn't be required.

I really don't understand why it works in a single-module project and not in my multi-module setup.

@scordio
Copy link

scordio commented Sep 28, 2023

@simasch out of curiosity, what is not required? The compiler plugin configuration?

@simasch
Copy link
Author

simasch commented Sep 28, 2023

Now I'm super confused!

@scordio Yes the compiler plugin config.

@SebastianDietrich After cleaning and adding the querydsl plugin that shouldn't be required anymore based on other issues it starts working again.

@SebastianDietrich
Copy link

Just checked - when I remove that plugin, it no longer works on my side.
Where do you have the info from, that it is no longer necessary?

@scordio
Copy link

scordio commented Sep 28, 2023

AFAIK, you have somehow to plug the com.querydsl.apt.jpa.JPAAnnotationProcessor into the compiling phase. This can be done via the maven-compiler-plugin or via the apt-maven-plugin.

I personally prefer the former to avoid third-party plugins but it's definitely personal taste.

@simasch
Copy link
Author

simasch commented Sep 28, 2023

@SebastianDietrich as I wrote I have a project where I don't need to use the plugin

@bwgjoseph
Copy link

AFAIK, you have somehow to plug the com.querydsl.apt.jpa.JPAAnnotationProcessor into the compiling phase. This can be done via the maven-compiler-plugin or via the apt-maven-plugin.

I personally prefer the former to avoid third-party plugins but it's definitely personal taste.

I've tried the compiler-plugin method but it doesn't generate for me as well. Have to fall back to apt-plugin.

@scordio
Copy link

scordio commented Sep 28, 2023

@simasch @bwgjoseph I just tried a simplified multi-module setup with the compiler plugin in a fresh Spring Boot 3.1.4: scordio/spring-boot-querydsl-example@3d68f80

It seems to work fine:

Screenshot 2023-09-28 at 18 55 11

I also tried the dependency-only config in a single module app and indeed it works fine, I guess because of the default annotation processors discovery process mentioned in the annotationProcessors parameter documentation. I wasn't aware of it! 🙂

Also, if I try the same in the multi-module example, it also works: scordio/spring-boot-querydsl-example@9c55cea

Could it be that you have a maven compiler configuration in a parent module that specifies some annotation processors? According to the annotationProcessors documentation, having specific annotation processors would prevent the automated discovery from the classpath.

For example, I tried to add the MapStruct processor, and the QueryDSL classes are no longer generated: scordio/spring-boot-querydsl-example@fe54d1b

@simasch
Copy link
Author

simasch commented Sep 28, 2023

Thank you very much @scordio

I'll investigate further tomorrow.

@bwgjoseph
Copy link

Thanks @scordio.

I do have other annotation processor where one of them is mapstruct. I think I tried some ordering but it wouldn't work for querydsl hence I have to fallback to apt plugin.

I'm not sure if it's apt plugin or intellij config, but intellij is not reliable in terms of regenerating the qclasses whenever I have changes. Hence, I have to run clean compile manually to get the updated qclass.

One more common scenario is when I create new class where I expect the qclass to also get generated but it doesn't.

@scordio
Copy link

scordio commented Sep 29, 2023

@bwgjoseph what if you try to rely on the automated discovery only? It means having the artifacts with the annotation processors as dependencies (with the provided scope to avoid them in the module package or as transitive dependencies) and no annotationProcessors configuration on the maven-compiler-plugin.

I've tried it in scordio/spring-boot-querydsl-example@a8911dd

@bwgjoseph
Copy link

I have to test it out but then again, there's further complication as well because the project also uses Lombok. Which there need to have configuration done for Lombok to work with mapstruct in the compiler plugin. :(

@arnosthavelka
Copy link

@simasch what do you mean by multi-maven project? To use it via dependency management or just in module? Because it seems working in my case -> see https://github.com/arnosthavelka/spring-advanced-training/blob/develop/sat-jpa/pom.xml. I also tried usage via dependency management (see https://github.com/arnosthavelka/spring-advanced-training/tree/querydsl-dependency-management-uasage) and it seems working as well.

I guess you just need always specify the classifier.

@exaucae
Copy link

exaucae commented Nov 6, 2023

facing the exact same issue. I first discribed it in the spring data mongo repository before being redirected here: spring-projects/spring-data-mongodb#4549.

My setup is using Kotlin and Gradle though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants