Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QueryDSL Q classes are generated in target folder but cannot be imported in other spring boot modules

I have multi module project (spring boot) and I configured QueryDSL in dao module it's working perfectly and it generated all Q classes. But when I import this module in service module and I import a Q class in the IDE (Intellij) it does not show any error but when running mvn clean install I get an error that the class is unresolved.

Unresolved reference: QRole

Here is the code for pom (dao module) :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <groupId>com.test.test</groupId>
        <artifactId>test-api</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <version>1.0.0-SNAPSHOT</version>

    <artifactId>dao</artifactId>
    <description>Module that have repositories and entities.</description>

    <dependencies>
        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- QueryDSL JPA -->
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>${querydsl.version}</version>
        </dependency>

        <!-- Database & JPA -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- Kotlin -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <querydsl.version>5.0.0</querydsl.version>
    </properties>

    <build>
        <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <configuration>
                    <compilerPlugins>
                        <plugin>jpa</plugin>
                        <plugin>spring</plugin>
                    </compilerPlugins>
                    <annotationProcessorPaths>
                        <annotationProcessorPath>
                            <groupId>com.querydsl</groupId>
                            <artifactId>querydsl-kotlin-codegen</artifactId>
                            <version>${querydsl.version}</version>
                        </annotationProcessorPath>
                        <annotationProcessorPath>
                            <groupId>com.querydsl</groupId>
                            <artifactId>querydsl-apt</artifactId>
                            <version>${querydsl.version}</version>
                            <classifier>jpa</classifier>
                        </annotationProcessorPath>
                    </annotationProcessorPaths>
                    <jvmTarget>1.8</jvmTarget>
                    <args>
                        <arg>-Xjsr305=strict</arg>
                    </args>
                </configuration>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <source>src/main/kotlin</source>
                                <source>src/main/resources</source>
                            </sourceDirs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>kapt</id>
                        <goals>
                            <goal>kapt</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>src/main/kotlin</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>process-test-sources</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>src/test/kotlin</sourceDir>
                                <sourceDir>target/generated-sources/kapt/test</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-noarg</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
like image 405
Noah13 Avatar asked Jan 31 '26 02:01

Noah13


1 Answers

The solution is:

  1. Right-click the project folder
  2. Select Maven
  3. Select Generate Sources And Update Folders

Then, Intellij automatically imports generated sources to the project.

like image 154
Muhammad Abdullah Aqib Avatar answered Feb 02 '26 17:02

Muhammad Abdullah Aqib