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")
}

0
5 comments

Can't reproduce:

 

Any errors when importing? Also check idea.log: https://intellij-support.jetbrains.com/hc/articles/207241085.

0
Avatar
Permanently deleted user

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.

val buildNumber = "local"
//val buildNumber: String by project

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.

0

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:

0
Avatar
Permanently deleted user

Unfortunately IntelliJ explicitly expects VM options in that field only.

Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/5.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Unrecognized option: -PbuildNumber=local
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

 

0

Please sign in to leave a comment.