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

JPAAnnotationProcessor with classifier jakarta fails with "Attempt to recreate a file for type" #3431

Closed
zenbones opened this issue Nov 22, 2022 · 11 comments
Labels

Comments

@zenbones
Copy link

zenbones commented Nov 22, 2022

Using querydsl 5.0.0, exact same setup in maven except one has no jakarta classifier and an 11 jvm, and the other adds the jakarta classifier and uses java 17. The java classifier plus java 17 version fails with "Attempt to recreate a file for type.."

  <dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <classifier>jakarta</classifier>
    <version>5.0.0</version>
  </dependency>
  <dependency>
    <groupId>com.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <classifier>jakarta</classifier>
    <version>5.0.0</version>
  </dependency>
        <plugin>
          <groupId>com.mysema.maven</groupId>
          <artifactId>apt-maven-plugin</artifactId>
          <version>1.1.3</version>
          <executions>
            <execution>
              <id>jpa</id>
              <goals>
                <goal>process</goal>
              </goals>
              <configuration>
                <outputDirectory>target/generated-sources/java</outputDirectory>
                <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
              </configuration>
            </execution>>
          </executions>
        </plugin>

In the jvm 11 non-jakarta case the apt processor executes only during the generate-sources phase, in the jvm 17 jakarta case the apt processor also executes on the compilation phase...

[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ smallmind-persistence ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 216 source files to C:\Users\david\Documents\Nutshell\empyrean\aeon\pantheon\org\smallmind\persistence\target\classes
Attempt to recreate a file for type org.smallmind.persistence.orm.jpa.QJPADurable
Attempt to recreate a file for type org.smallmind.persistence.orm.jpa.QTimestampedJPADurable
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Attempt to recreate a file for type org.smallmind.persistence.orm.jpa.QJPADurable
[ERROR] Attempt to recreate a file for type org.smallmind.persistence.orm.jpa.QTimestampedJPADurable
[INFO] 2 errors

This happens even when I add...

<phase>generate-sources</phase>

I think this setup is pretty vanilla. Anyone else with this issue?

@zenbones zenbones added the bug label Nov 22, 2022
@armyja
Copy link

armyja commented Nov 24, 2022

same. I use Java 8 and find that it generate extra files in target/generated-sources/annotations,which is duplicated with target/generated-sources/java.
image

@armyja
Copy link

armyja commented Nov 24, 2022

see this #3422 (comment)
remove apt-maven-plugin and it works, not generating files in target/generated-sources/java.

@zenbones
Copy link
Author

I had actually tried removing the maven plugin, noting that it runs twice, and was getting a stack overflow error. Tried this again upon your comment, thank you, and got the same error, but noted it's coming from the aspectj plugin. I resolved that by moving to the aspectj.dev version of that plugin, so all good. However, in the future, it might be nice/necessary to alter the compilation directory for the querydsl apt processing. This was possible using the plugin. Any way to do this now that I'm not using he plugin?

@PatrickGotthard
Copy link

PatrickGotthard commented Nov 28, 2022

The "jakarta"-variant of querydsl-apt provides a service declaration for javax.annotation.processing.Processor

image

Due to this, the Java compiler itself generates the Q-classes under target/generated-sources/annotation. To fix the error, you simply need to remove remove the apt-maven-plugin.

@eocak
Copy link

eocak commented Nov 28, 2022

The "jakarta"-variant of querydsl-apt provides a service declaration for javax.annotation.processing.Processor

image

Due to this, the Java compiler itself generates the Q-classes under target/generated-sources/annotation.

There are three possibilities to fix the error:

  • completely remove the apt-maven-plugin if you don't rely on any special config
  • set the outputDirectory to target/generated-sources/annotations
  • do not override the outputDirectory

image

How is this supposed to solve the problem since entity classes are not compiled into "Q" classes when apt-maven-plugin is changed?

@PatrickGotthard
Copy link

@eocak I don't understand what you mean -> the generation of the Q-classes works without problems. The problem is that the Q-classes may be generated twice in different packages by the compiler and the plugin

@eocak
Copy link

eocak commented Nov 28, 2022

@eocak I don't understand what you mean -> the generation of the Q-classes works without problems. The problem is that the Q-classes may be generated twice in different packages by the compiler and the plugin

My mistake. I supposed there was a problem with "Q" classes not read from annotations folder but it was something different. I handled it now. Thanks.

@zenbones
Copy link
Author

Having removed the maven plugin to avoid double generation of the Q sources, which does solve that problem btw, thank you, I was wondering if there was a way to alter the directory in which the Q sources are generated, sans plugin. This is not a huge deal as I can use the default annotations directory, but I was wondering.

By the way, my underlying problem is actually aspectj, which also runs annotation processing if you don't shut it off, because you can never have too much of a good thing, and aspectj calls on the eclipse compiler, and the that calls into JDT, the eclipse tools, and throws a stack overflow exception trying to handle jakarta persistence annotations like MappedSuperclass.

eclipse-jdt/eclipse.jdt.core#565

But all that is not a problem in the QueryDSL project, so I guess I can close this ticket. Thank you.

@vladimir0LYB
Copy link

Following the advice above, I removed the plugin. But I need to overwrite the generate directory(outputDirectory), what should I do?

@Jesega
Copy link

Jesega commented Apr 1, 2024

Hi! Is there a way to config the outputDierctory?

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

7 participants
@zenbones @PatrickGotthard @armyja @eocak @vladimir0LYB @Jesega and others