Search code examples
javacode-generationquerydsl

Java QueryDsl code generation does not generate Q class


I'm making a Spring project, where i'm using QueryDsl for the entities. I'm picking up this project from a few months back, where i already had 1 generated class (QUser). Now i made a new entity called Permission, and modified the User entity. When i'm building the project, the QUser doesn't change, and the QPermission class is not generating either. What am i doing wrong? Here's the entity and pom.xml for QueryDsl.

@Entity
@Table(name = "permission")
public class Permission {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;

   @Column(name = "name", length = 100, nullable = false)
   private String name;


   public Long getId() {
       return id;
   }

   public void setId(Long id) {
       this.id = id;
  }

    public String getName() {
       return name;
   }
    public void setName(String name) {
        this.name = name;
    }
}

And the pom.xml:

[..]
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</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>
    </plugins>
</build>
[...]

I was following the documentation: http://www.querydsl.com/static/querydsl/3.2.0/reference/html/ch03s03.html I'm using IntellIJ IDEA and tried the "Rebuild project" option as well.


Solution

  • Can you show the dependencies you put in your pom.xml ?

    I've made some tests starting from scratch

    Here are the dependencies :

    <dependencies>
        ...
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>4.2.1</version>
        </dependency>
        ...
    </dependencies>
    

    And the plugin :

            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    The complete source code I've tried to generate QFiles and that worked :

    https://github.com/githubjul/test-so-querydsl

    I don't run the project, only compile it to verify it works.