Cannot import JUnit5 with Gradle Kotlin DSL
Answered
IntelliJ doesn't seem to import the JUnit5 dependencies specified in my build.gradle.kts:
repositories {
mavenCentral()
jcenter()
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dependencies {
val commonsIoVersion = "2.6"
val gsonVersion = "2.8.5"
val jacksonDatabindVersion = "2.9.8"
val log4jCoreVersion = "2.11.2"
val picocliVersion = "3.9.5"
val postgresqlVersion = "42.2.5"
val springWebVersion = "5.1.5.RELEASE"
implementation("commons-io:commons-io:$commonsIoVersion")
implementation("com.google.code.gson:gson:$gsonVersion")
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonDatabindVersion")
implementation("org.apache.logging.log4j:log4j-core:$log4jCoreVersion")
implementation("info.picocli:picocli:$picocliVersion")
implementation("org.postgresql:postgresql:$postgresqlVersion")
implementation("org.springframework:spring-web:$springWebVersion")
val junitVersion = "5.5.0-M1"
val mockitoVersion = "2.27.0"
testCompile("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testCompile("org.mockito:mockito-core:$mockitoVersion")
testRuntime("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}

Please sign in to leave a comment.
Can't reproduce:
Any errors when importing? Also check idea.log: https://intellij-support.jetbrains.com/hc/articles/207241085.
I am able to gradle clean test build -PbuildNumber=local without errors.
It seems like IntelliJ's auto sync does not pull the dependency in if there is an error. In my case, I have a gradle parameter that should have an expected value, but since there is no way to set a parameter for the auto sync process, it fails.
Doing this resolved the issue and auto sync worked, but I'm wondering why running gradle clean test build -PbuildNumber=local did not pull the external library.
The library may be present in your local repo, but not added in IntelliJ IDEA module dependencies since the sync fails because of the error.
You can try adding the option here:
Unfortunately IntelliJ explicitly expects VM options in that field only.
You are right, it's a known limitation:
https://youtrack.jetbrains.com/issue/IDEA-132726
https://stackoverflow.com/a/47259746/104891