Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to querydsl with spring-data-mongodb and gradle #2617

Closed
viktorgt opened this issue Jun 21, 2020 · 3 comments
Closed

How to querydsl with spring-data-mongodb and gradle #2617

viktorgt opened this issue Jun 21, 2020 · 3 comments
Labels

Comments

@viktorgt
Copy link

viktorgt commented Jun 21, 2020

I'm unable to configure gradle to generate the query types for Querydsl. Following advices like #2444, my configuration looks as follows:

plugins {
	id 'org.springframework.boot' version '2.3.1.RELEASE'
	id 'io.spring.dependency-management' version '1.0.9.RELEASE'
	id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
	implementation 'org.springframework.boot:spring-boot-starter-web'

	compile 'com.querydsl:querydsl-mongodb:4.3.1'
	annotationProcessor 'com.querydsl:querydsl-apt:4.3.1:morphia'
	annotationProcessor 'org.springframework.boot:spring-boot-starter-data-mongodb'
}

The query types are not generated.
Gradle version: 6.4.1

Unfortunately, the documentation provides only a configuration for maven and all other guides on the web seem to be deprecated.

Sample repository: https://github.com/viktorgt/spring-mongo-querydsl

@somudas93
Copy link

somudas93 commented Jul 11, 2020

Hi @viktorgt please try this, I'm able to generate the Q-Classes with this.. hope it helps you and its also running for me.. Note I'm not using the Morphia annotations and the dependency, instead i'm using @com.querydsl.core.annotations.QueryEntity and as for your build.gradle

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

dependencies {
   //your general spring data and other spring dependencies
   compileOnly 'com.querydsl:querydsl-apt'
   compile 'com.querydsl:querydsl-mongodb:4.3.1'
   compile 'com.querydsl:querydsl-core'

   annotationProcessor ('com.querydsl:querydsl-apt:4.3.1:general', 'javax.annotation:javax.annotation-api')
}

//Your path can be as per your choice of source directory for the Q-Classes mine is /src/main/generated/

def queryDslOutput = file(new File(projectDir, '/src/main/generated/'))
sourceSets {
    generated {
        java {
            srcDir queryDslOutput
        }
    }
}

compileJava {
	options.compilerArgs << '-s'
	options.compilerArgs << "$projectDir/src/main/generated/"
	
	doFirst {
		file(new File(projectDir, '/src/main/generated/')).mkdirs();
	}
}

Edit: I'm also not using the JPA Annotations or the Spring-Data-JPA
Gradle Version: 6.5

P.S: I've edited this comment a lot of times, because I'm new to Github.

@viktorgt
Copy link
Author

viktorgt commented Jul 11, 2020

@somudas93 thank you. This one actually works 👍

@PhilippS93
Copy link

PhilippS93 commented Oct 22, 2020

We could also add delete(files("${projectDir}/src/main/generated/")) in the doFirst part of the compileJava, so old files will be overridden, when there are changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants