Querydsl Annotation Processor issue after upgrade to Gradle 5 - java

I have a gradle script which generates querydsl classes from Mongo annotated entities. It was working so far, but after upgrade to Gradle 5 I have a problem with:
* What went wrong:
Execution failed for task ':myproject-common:compileQuerydsl'.
Annotation processor 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor' not found
Please find my gradle.build script below. Any ideas what could be wrong? I read that there was change in Gradle 5 that annotation processors are not used by default during compilation and annotationProcessor declaration should be added but when I add it to dependencies the same error occurs.
plugins {
id 'org.springframework.boot' version '2.0.4.RELEASE'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
repositories {
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
jar {
enabled = true
baseName = 'myproject-common'
version = '0.0.1-SNAPSHOT'
}
// do no package commons into fat jar
bootJar {
enabled = false
}
querydsl {
library = 'com.querydsl:querydsl-apt:4.1.4'
querydslSourcesDir = 'src/main/querydsl'
springDataMongo = true
}
sourceCompatibility = 11.0
targetCompatibility = 11.0
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/main/querydsl']
}
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.data:spring-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-security")
compile("com.fasterxml.jackson.datatype:jackson-datatype- jsr310:2.8.6")
compile("com.google.guava:guava:23.0")
compile("commons-io:commons-io:2.5")
compile("org.aspectj:aspectjweaver:1.8.9")
compile("org.apache.commons:commons-lang3:3.5")
compile("commons-collections:commons-collections:3.2.2")
compile("org.javamoney:moneta:1.1")
compile("com.fizzed:rocker-runtime:1.2.0")
compile("com.querydsl:querydsl-core:4.1.4")
compile("com.querydsl:querydsl-mongodb:4.1.4")
compile("com.querydsl:querydsl-apt:4.1.4")
compile("com.codepoetics:protonpack:1.15")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.assertj:assertj-core:3.7.0")
}

This is my working configuration for JPA without using additional plugins. Gradle 5.3, openjdk 11.0.2.
plugins {
id 'java-library'
}
ext {
springBootVersion = '2.2.0.M1'
queryDslVersion = '4.2.1'
}
dependencies {
api(
"com.querydsl:querydsl-jpa:$queryDslVersion"
)
implementation(
platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"),
'org.springframework.boot:spring-boot-starter-validation',
'org.springframework.boot:spring-boot-starter-data-jpa',
'org.liquibase:liquibase-core',
'org.postgresql:postgresql'
)
annotationProcessor(
platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion"),
'jakarta.persistence:jakarta.persistence-api',
'jakarta.annotation:jakarta.annotation-api',
"com.querydsl:querydsl-apt:$queryDslVersion:jpa"
)
}
Please pay attention to the annotation processor. It has suffix ":jpa". Probably this is what you missed. To activate the same one for mongodb you should add ":morphia" suffix.
Please also look at these 2 dependencies:
'jakarta.persistence:jakarta.persistence-api'
'jakarta.annotation:jakarta.annotation-api'
This is a workaround for the issue described here:
https://discuss.gradle.org/t/annotationprocessor-querydsl-java-lang-noclassdeffounderror/27107
They should be transitive dependencies of the annotation processor, but they aren't yet. Probably you will have to include some mongo dependencies to annotationProcessor too.
Generated sources are located in \build\generated\sources\annotationProcessor\java\main

I have finally found a workaround. Querydsl's lack of compatibility with Gradle 5 is reported here as a bug: https://github.com/ewerk/gradle-plugins/issues/108
Workaround is to add to gradle script:
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}

I could solve the problem by adding the following two dependencies.
annotationProcessor "com.querydsl:querydsl-apt:4.2.1:jpa"
annotationProcessor 'javax.annotation:javax.annotation-api:1.3.1'
The second dependency was a hidden reason why it not worked for me.

I faced the same issue for Spring Boot Data JPA and Query DSL with Gradle 6.6.1. I tried so many things in my build.gradle file, including some of the suggestions in other responses to this question. I was able to come up with a build.gradle file with a minimal set of additions to the standard build file (standard in the sense of the one generated by https://start.spring.io). Here it is:
plugins {
id 'org.springframework.boot' version '2.4.0'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'com.ewerk.gradle.plugins.querydsl' version "1.0.10"
}
group = 'org.code'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
querydsl {
querydslDefault = true
jpa = true
}
configurations {
querydsl.extendsFrom implementation
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
ext {
queryDslVersion = '4.4.0'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
The key addition is the Query DSL plugin:
id 'com.ewerk.gradle.plugins.querydsl' version "1.0.10"
However, it is not enough on its own. Other important additions are:
querydsl {
querydslDefault = true
jpa = true
}
configurations {
querydsl.extendsFrom implementation
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}

The configuration i am using,it works:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
group = 'io.loremipsum'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
querydsl {
library = 'com.querydsl:querydsl-apt:4.1.4'
querydslSourcesDir = 'src/main/querydsl'
springDataMongo = true
}
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/main/querydsl']
}
}
}
// is required when gradle > 5.0
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
compile 'org.springframework.boot:spring-boot-starter-web'
compile("com.querydsl:querydsl-core:4.1.4")
compile("com.querydsl:querydsl-mongodb:4.1.4")
compile("com.querydsl:querydsl-apt:4.1.4")
compile 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
}
pay attention to the dependency declaration:
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation dependency should not be used or will result in an exception:
Annotation processor 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor' not found

I see you have compile("com.querydsl:querydsl-apt:4.1.4") in your dependencies. According to the docs
Since implementation details matter for annotation processors, they must be declared separately on the annotation processor path. Gradle ignores annotation processors on the compile classpath.
So, put com.querydsl:querydsl-apt:4.1.4 in the annotationProcessor scope.
BTW, consider switching to api / implementation scopes over compile.

Related

Gradle Not Finding Method Implementation for Arguments

I am trying to build a simple maven library and I can't get it to build. I am using Gradle Groovy and Kotlin Multiplatform Library in IntelliJ IDEA.
I haven't even been able to begin coding since my dependencies wont load. I am very new to all this so bare with me.
This is my build.gradle
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.7.10'
}
group = 'me.me'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies{
implementation platform("io.cucumber:cucumber-bom:7.1.0")
implementation 'io.cucumber:cucumber-java'
implementation 'io.cucumber:cucumber-junit-platform-engine'
implementation 'io.cucumber:cucumber-junit'
implementation 'io.cucumber:cucumber-spring'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = '1.8'
}
withJava()
testRuns["test"].executionTask.configure {
useTestNG()
}
}
sourceSets {
commonMain {
}
commonTest {
dependencies {
implementation kotlin('test')
}
}
}
}
and this is the error I am getting
Build file '/Users/Me/Documents/GitHub/Project-Tools/build.gradle' line: 13
A problem occurred evaluating root project 'Project-Tools'.
> Could not find method implementation() for arguments
[DefaultExternalModuleDependency{group='io.cucumber', name='cucumber-bom', version='7.1.0', configuration='default'}]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I even tried commenting out each dependency one at a time so see if any work and none did
EDIT: Also I am on a Mac

Gradle Java Spring boot project with Jooq JPADatabase does not detect entities

I am trying to generate jOOQ (v.3.14.8) classes from JPA-annotated entities (#Entity) in a Gradle Spring Boot (v.2.4.3) project with the nu.studer.jooq plugin (v.5.2.1) and the JPADatabase as database.
Whenever I run ./gradlew generateJooq no files are generated in the target folder with the following INFO:
INFO: No modified files: This code generation run has not produced any file modifications.
This means, the schema has not changed, and no other parameters (jOOQ version, driver version, database version,
and any configuration elements) have not changed either.
In automated builds, it is recommended to prevent unnecessary code generation runs. This run took: 283.126ms
Possible means to prevent this:
- Use manual code generation and check in generated sources: https://www.jooq.org/doc/latest/manual/code-generation/codegen-version-control/
- Use schema version providers: https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-database/codegen-database-version-providers/
- Use gradle tasks and inputs: https://github.com/etiennestuder/gradle-jooq-plugin/blob/master/README.md
Mar 12, 2021 3:35:02 PM org.jooq.tools.JooqLogger info
INFO: Removing excess files
BUILD SUCCESSFUL in 2s
It looks to me like the entities are not being picked up.
Here is my build.gradle file:
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'nu.studer.jooq' version '5.2.1'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation('org.springframework.boot:spring-boot-starter-jooq')
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
jooqGenerator 'org.jooq:jooq-meta-extensions-hibernate'
}
test {
useJUnitPlatform()
}
jooq {
// version = dependencyManagement.importedProperties['jooq.version'] // use jOOQ version defined in Spring Boot
version = '3.14.8' // specify jOOQ version
configurations {
main {
generationTool {
// logging = org.jooq.meta.jaxb.Logging.WARN
generator {
name = 'org.jooq.codegen.DefaultGenerator'
strategy.name = 'org.jooq.codegen.DefaultGeneratorStrategy'
database {
name = 'org.jooq.meta.extensions.jpa.JPADatabase'
properties {
property {
key = 'packages'
value = 'com.example.jooq.entities'
}
property {
key = 'useAttributeConverters'
value = true
}
}
}
target {
packageName = 'com.example.jooq.generated.jooq.entities'
directory = 'target/generated-sources/jooq'
}
}
}
}
}
}
The sample code for this implementation can be found here.
Thanks for your help already, really appreciate.

java.lang.ClassNotFoundException: org.postgresql.Driver from jooq code generating task

I am implementing java-spring-boot project ( jdk11, spring boot 2.3.0.RELEASE ) using jooq-hikari-hibernate-postgres for back end.
I have already created the tables using flyway.
I have created a task name "generateJooqRepo" in build.gradle to generate the java code for the repository. The task is running however failing with error message:
Execution failed for task ':generateJooqRepo'.
> java.lang.ClassNotFoundException: org.postgresql.Driver
Any insight on what I am doing wrong?
build.gradle:
import org.jooq.codegen.*
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE'
id 'org.flywaydb.flyway' version '6.4.4'
id "nu.studer.jooq" version "4.2"
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'jacoco'
apply plugin: 'idea'
apply plugin: 'nu.studer.jooq'
configurations {
deployerJars
}
sourceCompatibility = '11.0.1'
targetCompatibility = '11.0.1'
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
}
dependencies {
//Spring Dependencies
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.3.0.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE'
//postges
jooqRuntime 'org.postgresql:postgresql:42.2.14'
implementation 'org.postgresql:postgresql:42.2.14'
//The gradle-jooq-plugin needs dependencies in a separate configuration.
// It uses the jooqRuntime configuration to detect the needed dependencies, it doesn't use the compile or implementation configuration.
jooqRuntime group: 'org.jooq', name: 'jooq-meta-extensions', version: '3.13.2'
//flyway
compile 'org.flywaydb:flyway-core:6.4.4'
//jooq dependency
implementation 'org.springframework.boot:spring-boot-starter-jooq:2.3.0.RELEASE'
compile 'org.jooq:jooq:3.13.2'
compile 'org.jooq:jooq-meta:3.13.2'
compile 'org.jooq:jooq-codegen:3.13.2'
// This dependency is found on compile classpath of this component.
implementation 'org.apache.commons:commons-lang3:3.9'
}
group = 'com.ringo.tapos.service'
version = '1.0.0-SNAPSHOT'
mainClassName = "com.ringo.tapos.service.Application"
// Use your favourite XML builder to construct the code generation configuration file
// ----------------------------------------------------------------------------------
task generateJooqRepo {
doLast {
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd') {
jdbc() {
driver('org.postgresql.Driver')
url('jdbc:postgresql://localhost:5432/postgres')
user('postgres')
password('postgres')
schema('tapos')
}
generator() {
database() {
}
generate([:]) {
pojos true
daos true
relations true
deprecated false
records true
//immutablePojos false
}
target() {
packageName('com.ringo.tapos.service.repositories')
directory('src/main/java')
}
}
}
GenerationTool.generate(writer.toString())
}
}
You should add postgres driver dependency to jooqRuntime configuration as well
jooqRuntime 'org.postgresql:postgresql:42.2.14'
UPDATE:
You should add postgres driver to your buildscript classpath if you want to use it in gradle script outside of the tasks provided by nu.studer.jooq plugin
buildscript {
dependencies {
classpath 'org.postgresql:postgresql:42.2.14'
}
}

using springboot with local elastic-search instance not working

I want to use elasticSearch repository inside a spring boot application .
I have a local running instance of elastic search 5.5.2
I've search for a while, tried so many combinations of the several sources but nothing yield a working solution , and right now I'm stuck with error :
Error creating bean with name 'elasticsearchTemplate'
what am i doing wrong ?
This is my main class
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class Application {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger("chapters.introduction.HelloWorld1");
try
{
SpringApplication.run(Application.class, args);
}
catch(Exception e)
{
logger.info("caught an exception",e);
}
}
}
config class
#Configuration
#EnableElasticsearchRepositories(basePackages = "hello")
#ComponentScan(basePackages = {"hello"})
public class config {
#Bean
public NodeBuilder nodeBuilder() {
return new NodeBuilder();
}
#Bean
public ElasticsearchOperations elasticsearchTemplate() {
Settings.Builder elasticsearchSettings =
Settings.settingsBuilder()
.put("http.enabled", "false") // 1
.put("path.data", "/home/nad/elasticsearch_data") // 2
.put("path.home", "/home/nad/Downloads/elasticsearch-5.5.2"); // 3
return new ElasticsearchTemplate(nodeBuilder()
.local(true)
.settings(elasticsearchSettings.build())
.node()
.client());
}
}
my build.gradle file
group 'FirstWebServer'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
maven { url "http://repo.spring.io/milestone" }
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '1.2.5.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.0.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.0.0.M6', ext: 'pom'
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.18'
testCompile("junit:junit")
}
what is the proper way of configuration ? some examples shows application.properties configuration , some dont .
What about compatability , some shows that only elasticsearch 2. * or lower, some said that 5
Its really confusing :(
Thank you very much for your help
To use Elasticsearch 5.x you need Spring Data release Kay (already released), which is only part of Spring Boot 2 (to be released soon). Right now your only option really is to use the latest Spring Boot 2 build and wait for a stable release.
Some people tried using Spring Data Kay with Spring boot 1.5, but ended up in dependency hell. Probably not worth the pain with Spring Boot 2 just around the corner.

JUnit 5 under Gradle with multiple source sets

I've got a project I'm putting together that I want to use JUnit 5 for. I've got this working fine for Unit Tests already.
I do however have multiple test source sets - I've got an additional one for Acceptance Tests. I'm struggling to work out how to get JUnit 5 to run the Unit Tests - defined in src/test - in one task and the Acceptance Tests - defined in the "acceptanceTest" sourceSet and located in "src/acceptance" - in another task.
I have previously got this working with JUnit 4 and Cucumber, but the JUnit 5 plugin doesn't seem to want to work like this.
build.gradle:
buildscript {
ext {
jackson_version = "2.9.0.pr4"
// IntelliJ needs M4
junitJupiter_version = "5.0.0-M4"
junitPlatform_version = "1.0.0-M4"
kotlin_version = "1.1.3-2"
slf4j_version = "1.7.25"
spring_version = "4.3.10.RELEASE"
springBoot_version = "1.5.4.RELEASE"
springBootAdmin_version = "1.5.2"
runAcceptance = System.properties['noAcceptance'] == null
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "com.github.ben-manes:gradle-versions-plugin:0.15.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatform_version"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBoot_version"
}
}
plugins {
id "com.github.ben-manes.versions" version "0.15.0"
}
apply plugin: "com.github.ben-manes.versions"
apply plugin: "kotlin"
apply plugin: "kotlin-spring"
apply plugin: "org.junit.platform.gradle.plugin"
apply plugin: "org.springframework.boot"
apply plugin: "war"
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
sourceSets {
acceptanceTest {
kotlin {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/acceptance/kotlin')
}
resources.srcDir file('src/acceptance/resources')
}
}
configurations {
acceptanceTestCompile.extendsFrom testCompile
acceptanceTestRuntime.extendsFrom testRuntime
}
dependencies {
compile "com.graphql-java:graphql-java-tools:3.1.3"
compile "com.graphql-java:graphql-spring-boot-starter:3.5.0"
compile "com.zaxxer:HikariCP:2.6.3"
compile("de.codecentric:spring-boot-admin-server:$springBootAdmin_version") {
exclude group: "junit", module: "junit"
}
compile("de.codecentric:spring-boot-admin-server-ui:$springBootAdmin_version") {
exclude group: "junit", module: "junit"
}
compile("de.codecentric:spring-boot-admin-starter-client:$springBootAdmin_version") {
exclude group: "junit", module: "junit"
}
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.slf4j:slf4j-api:$slf4j_version"
compile "org.springframework:spring-jdbc:$spring_version"
compile "org.springframework.boot:spring-boot-starter-web:$springBoot_version"
compile "org.springframework.boot:spring-boot-starter-actuator:$springBoot_version"
compile "ru.yandex.qatools.embed:postgresql-embedded:2.2"
runtime "ch.qos.logback:logback-classic:1.2.3"
runtime "org.jolokia:jolokia-core:1.3.7"
runtime "org.liquibase:liquibase-core:3.5.3"
runtime "org.postgresql:postgresql:42.1.3"
runtime "org.slf4j:jcl-over-slf4j:$slf4j_version"
runtime "org.slf4j:jul-to-slf4j:$slf4j_version"
testCompile "com.github.sbrannen:spring-test-junit5:1.0.0.M4"
testCompile "com.nhaarman:mockito-kotlin:1.5.0"
testCompile("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") {
exclude group: "junit", module: "junit"
}
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiter_version"
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitJupiter_version"
acceptanceTestCompile "org.springframework.boot:spring-boot-starter-test:$springBoot_version"
}
task acceptanceTest(type: Test) {
testClassesDirs = sourceSets.acceptanceTest.output.classesDirs
classpath = sourceSets.acceptanceTest.runtimeClasspath
outputs.upToDateWhen { false }
}
if (ext.runAcceptance) {
check.dependsOn acceptanceTest
}
acceptanceTest.mustRunAfter test
task wrapper(type: Wrapper) {
gradleVersion = "4.0"
}
Since Gradle 4.6 the gradle Java plugin has JUnit 5 support
So once you have configured the test source sets, the setup is as simple as follows - for my test and intTest test tasks I just need to configure this to use JUnit5:
apply plugin: 'java'
test {
useJUnitPlatform()
}
intTest {
useJUnitPlatform()
}
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api:5.1.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.0")
}
To refine existing answers, you need to configure each of your Test-type tasks to include useJUnitPlatform(). In your concrete example this would look like
task acceptanceTest(type: Test) {
useJUnitPlatform()
testClassesDirs = sourceSets.acceptanceTest.output.classesDirs
classpath = sourceSets.acceptanceTest.runtimeClasspath
outputs.upToDateWhen { false }
}
You can also do this centrally via
tasks.withType(Test) {
useJUnitPlatform()
}
The JUnit 5 plugin only creates one task - junitPlatformTest, and bases it on the junitPlatform extension.
If you want to run acceptance tests, or any other type of tests in another source set independently, you'll need to create your own JavaExec task, like the plugin does.
See: https://github.com/junit-team/junit5/blob/master/junit-platform-gradle-plugin/src/main/groovy/org/junit/platform/gradle/plugin/JUnitPlatformPlugin.groovy#L66
You might want to create a task like this:
task e2eTest(
type: JavaExec,
description: 'Runs the e2e tests.',
group: 'Verification'
) {
dependsOn testClasses
shouldRunAfter test
classpath = sourceSets.e2e.runtimeClasspath
main = 'org.junit.platform.console.ConsoleLauncher'
args = ['--scan-class-path',
sourceSets.e2e.output.getClassesDirs().asPath,
'--reports-dir', "${buildDir}/test-results/junit-e2e"]
}

Categories