Hi,
I am new to Querydsl and trying to use it in a simple test project. I followed the official tutorial to configure my
pom.xml, then mvn clean install was able to generated the Q Classes under target/generated-sources/java. But I got the
error below:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project
spring-jqgrid-tutorial: Compilation failure
[ERROR] /D:/Project/spring-jqgrid-tutorial/src/main/java/org/krams/controller/UserController.java:[92,62] package
QUser.user does not exist
I think the root cause is the generated Q class source files were not compiled automatically into binary class files. I
did verify there are no QUser.class under my project directory. I also tried to use build-helper-maven-plugin to add
target/generated-sources/java as a source folder and specify target/generated-sources/java as an additional source root in
apt-maven-plugin configuration. But I got no luck.
Here is my pom.xml
<properties>
<querydsl.version>3.3.2</querydsl.version>
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.apt.plugin.version>1.1.1</maven.apt.plugin.version
<maven.build.helper.plugin.version>1.8</maven.build.helper.plugin.version>
<properties>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<scope>provided</scope>
</dependency>
<dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.build.helper.plugin.version}</version>
<executions>
<execution>
<id>add-source</id>
<phase>process-classes</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${maven.apt.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
<additionalSourceRoots>
<additionalSourceRoot>target/generated-sources/java</additionalSourceRoot>
</additionalSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugins>
And here is the generated QUser.java
package org.krams.domain;
import static com.mysema.query.types.PathMetadataFactory.*;
import com.mysema.query.types.path.*;
import com.mysema.query.types.PathMetadata;
import javax.annotation.Generated;
import com.mysema.query.types.Path;
import com.mysema.query.types.path.PathInits;
/**
* QUser is a Querydsl query type for User
*/
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QUser extends EntityPathBase<User> {
private static final long serialVersionUID = -1712499619L;
private static final PathInits INITS = PathInits.DIRECT2;
public static final QUser user = new QUser("user");
public final NumberPath<Integer> age = createNumber("age", Integer.class);
public final StringPath firstName = createString("firstName");
public final NumberPath<Long> id = createNumber("id", Long.class);
public final StringPath lastName = createString("lastName");
public final StringPath password = createString("password");
public final QRole role;
public final StringPath username = createString("username");
public QUser(String variable) {
this(User.class, forVariable(variable), INITS);
}
public QUser(Path<? extends User> path) {
this(path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
}
public QUser(PathMetadata<?> metadata) {
this(metadata, metadata.isRoot() ? INITS : PathInits.DEFAULT);
}
public QUser(PathMetadata<?> metadata, PathInits inits) {
this(User.class, metadata, inits);
}
public QUser(Class<? extends User> type, PathMetadata<?> metadata, PathInits inits) {
super(type, metadata, inits);
this.role = inits.isInitialized("role") ? new QRole(forProperty("role"), inits.get("role")) : null;
}
}
Appreciate your help and comments. I can provide more information if required.