I’m having trouble setting up JUnit 5 with Gradle for my project. I’m trying to run integration tests using the integrationTest task, but I keep getting the following error:
package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.Test;
Here is my build.gradle configuration:
buildscript {
repositories {
mavenCentral()
maven { url 'https://s01.oss.sonatype.org' }
gradlePluginPortal()
mavenLocal()
google()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
// Add any required dependencies here for the build script
}
}
allprojects {
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
idea {
module {
outputDir file('build/classes/java/main')
testOutputDir file('build/classes/java/test')
}
}
}
configure(subprojects) {
apply plugin: 'java-library'
sourceCompatibility = 11
compileJava {
options.incremental = true
}
compileJava.doLast {
def assetsFolder = new File("${project.rootDir}/assets/")
def assetsFile = new File(assetsFolder, "assets.txt")
assetsFile.delete()
fileTree(assetsFolder).collect { assetsFolder.relativePath(it) }.each {
assetsFile.append(it + "n")
}
}
}
subprojects {
version = '1.0.0'
ext.appName = 'ccpclient'
repositories {
mavenCentral()
maven { url 'https://s01.oss.sonatype.org' }
mavenLocal()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://jitpack.io' }
}
}
eclipse.project.name = 'ccpclient' + '-parent'
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('test/')
}
}
}
dependencies {
// Use JUnit 5 instead of JUnit 4
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
implementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
}
task integrationTest(type: Test) {
useJUnitPlatform() // Make sure to use the JUnit Platform (JUnit 5)
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
Despite having the JUnit 5 dependencies defined, I’m still encountering the “package org.junit.jupiter.api does not exist” error.
I’ve ensured that the integrationTest source set includes the test output in its classpath, and I’ve also specified the useJUnitPlatform() method for the integrationTest task.
Any suggestions on what might be wrong or what I’m missing? Thanks in advance for your help!