IntelliJ won't run QueryDSL code generation

Viewed 14

I'm using QueryDSL in this project and I'm exploring the feasibility of QueryDSL for my organization. Here is what I'm experiencing.

When I run mvn clean compile, everything works as expected. AllQueryDSL stuff is generated properly, IntelliJ detects all the generated sources and offers full intellisense for them.

When I run the build from the Build -> Build Project menu, IntelliJ does not run the annotation processors and gives me compile errors wherever I am referencing the generated sources.

If I run mvn clean compile and then Build -> Build Project, it works because the previous CLI command had generated the sources.

If I right click on the root of my project tree and select Maven -> Generate Sources & Update Folders, it runs the annotation processors and generates all the QueryDSL stuff. I can then run Build -> Build Project after that.

My goal is to figure out how to get the annotation processor stuff to run when I click Build -> Build Project. I do not understand why this is happening.

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.me</groupId>
    <artifactId>alternate-query-experiment-java</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>alternate-query-experiment-java</name>
    <description>alternate-query-experiment-java</description>

    <properties>
        <java.version>18</java.version>
        <maven.git.hooks.version>1.0.0</maven.git.hooks.version>
        <git.hook.plugin.version>3.3.0</git.hook.plugin.version>
        <faker.version>1.0.2</faker.version>
        <querydsl.version>5.0.0</querydsl.version>
        <apt.plugin.version>1.1.3</apt.plugin.version>
        <mapstruct.version>1.5.2.Final</mapstruct.version>
        <spotless.version>2.26.0</spotless.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${mapstruct.version}</version>
        </dependency>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.javafaker</groupId>
            <artifactId>javafaker</artifactId>
            <version>${faker.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.yaml</groupId>
                    <artifactId>snakeyaml</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>${spotless.version}</version>
                <configuration>
                    <java>
                        <googleJavaFormat />
                    </java>
                    <sql>
                        <includes>
                            <include>src/main/resources/db/migration/*.sql</include>
                        </includes>
                        <dbeaver />
                    </sql>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>apply</goal>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.rudikershaw.gitbuildhook</groupId>
                <artifactId>git-build-hook-maven-plugin</artifactId>
                <version>${git.hook.plugin.version}</version>
                <configuration>
                    <installHooks>
                        <pre-commit>spotless-apply</pre-commit>
                    </installHooks>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>install</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>io.me</groupId>
                        <artifactId>maven-git-hooks</artifactId>
                        <version>${maven.git.hooks.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>${apt.plugin.version}</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.querydsl</groupId>
                        <artifactId>querydsl-apt</artifactId>
                        <version>${querydsl.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>
0 Answers
Related