1

I am trying to use querydsl in my project like it is described here in spring boot documentation, springboot-mongodb-look at 5.3.4 so that I can do this,

QPerson person = new QPerson("person");
List<Person> result = repository.findAll(person.address.zipCode.eq("C0123"));

Page<Person> page = repository.findAll(person.lastname.contains("a"), 
                                       new PageRequest(0, 2, Direction.ASC, "lastname"));

I am using gradle build and mongodb for database.

My problem is, in querydsl documentation, only the maven integration is provided. querydsl document link i.e

<dependency>
  <groupId>com.querydsl</groupId>
  <artifactId>querydsl-apt</artifactId>
  <version>${querydsl.version}</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>com.querydsl</groupId>
  <artifactId>querydsl-mongodb</artifactId>
  <version>${querydsl.version}</version>
</dependency>

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.1</version>
</dependency>

And now, configure the Maven APT plugin which generates the query types used by Querydsl:

<project>
  <build>
    <plugins>
      ...
      <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.morphia.MorphiaAnnotationProcessor</processor>
            </configuration>
          </execution>
        </executions>
      </plugin>
    ...
    </plugins>
  </build>
</project>

Can this be integrated using gradle? If yes, please provide the solution.

Debanjan
  • 2,817
  • 2
  • 24
  • 43

3 Answers3

0

Take a look at querydsl-with-gradle-and-idea and Configuring QueryDSL for Spring Data and MongoDB with Gradle:

They use:

compile "com.mysema.querydsl:querydsl-apt:3.6.3:jpa"
compile "com.querydsl.apt:querydsl-mongodb:4.0.9"

and github corneil's spring-data-demo's complete example, detailed here: QueryDSL for Mongo with Spring and gradle

Community
  • 1
  • 1
alexbt
  • 16,415
  • 6
  • 78
  • 87
0

For me helped this article add Querydslsupport

Add to your gradle file next:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.9"
    }
}

apply plugin: 'com.ewerk.gradle.plugins.querydsl'

sourceSets {
    main {
        java {
            srcDir "$buildDir/generated/source/app/main"
        }
    }
}

dependencies {
    compile "com.querydsl:querydsl-mongodb:4.1.4"
    compileOnly "com.querydsl:querydsl-apt:4.1.4"
}

querydsl {
    springDataMongo = true
    querydslSourcesDir = "$buildDir/generated/source/app/main"
}

After that you should add @Document annotation to your entity class and just build. You'll see generated Q files under folder specified in querydslSourcesDir.

Max
  • 766
  • 9
  • 19
0

This is what worked for me with QueryDSL MongoDB 4.4.0 and Gradle 7.

  1. Add the following dependencies to your build.gradle file.

    implementation "com.querydsl:querydsl-mongodb:4.4.0"
    annotationProcessor("com.querydsl:querydsl-apt:4.4.0:general", "javax.annotation:javax.annotation-api")
    

    Note: We need javax.annotation:javax.annotation-api in there so that the APT processor can understand the @NotNull etc. in your domain classes.

  2. Annotate your domain classes with @QueryEntity annotation from com.querydsl.core.annotations package (from the first dependency above).

Let Gradle to it's magic and you will see the QClasses .

Yohan Liyanage
  • 6,840
  • 3
  • 46
  • 63