I’m trying to add the io.mockk:mockk:1.12.3
dependency to my Kotlin Multiplatform project using Gradle Kotlin DSL. When using testImplementation("io.mockk:mockk:1.12.3")
I get:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public fun ArtifactHandler.testImplementation(artifactNotation: Any): PublishArtifact defined in org.gradle.kotlin.dsl
public fun ArtifactHandler.testImplementation(artifactNotation: Any, configureAction: Action<ConfigurablePublishArtifact>): PublishArtifact defined in org.gradle.kotlin.dsl
public fun DependencyConstraintHandler.testImplementation(constraintNotation: Any): DependencyConstraint? defined in org.gradle.kotlin.dsl
public fun DependencyConstraintHandler.testImplementation(constraintNotation: Any, block: Action<DependencyConstraint>): DependencyConstraint defined in org.gradle.kotlin.dsl
public fun <T : Dependency> DependencyHandler.testImplementation(dependency: TypeVariable(T), action: Action<TypeVariable(T)>): TypeVariable(T) defined in org.gradle.kotlin.dsl
public fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? defined in org.gradle.kotlin.dsl
public fun DependencyHandler.testImplementation(group: String, name: String, version: String? = ..., configuration: String? = ..., classifier: String? = ..., ext: String? = ..., dependencyConfiguration: Action<ExternalModuleDependency>? = ...): ExternalModuleDependency defined in org.gradle.kotlin.dsl
public fun DependencyHandler.testImplementation(dependencyNotation: String, dependencyConfiguration: Action<ExternalModuleDependency>): ExternalModuleDependency defined in org.gradle.kotlin.dsl
public fun DependencyHandler.testImplementation(dependencyNotation: Provider<*>, dependencyConfiguration: Action<ExternalModuleDependency>): Unit defined in org.gradle.kotlin.dsl
public fun DependencyHandler.testImplementation(dependencyNotation: ProviderConvertible<*>, dependencyConfiguration: Action<ExternalModuleDependency>): Unit defined in org.gradle.kotlin.dsl
When I instead use the normal implementation("io.mockk:mockk:1.12.3")
call, gradle fails at downloading mockk-1.12.3-samplessources.jar
which I guess it tries to obtain due to the implementation type.
Has anybody got an idea why I can’t use testImplementation
? Here’s my gradle.build.kts
:
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
}
}
plugins {
kotlin("multiplatform") version "1.5.31"
kotlin("plugin.serialization") version "1.4.10"
id("com.github.johnrengelman.shadow") version "7.1.2"
application
}
group = "com.example.project"
version = "1.0-SNAPSHOT"
repositories {
jcenter()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}
kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
testRuns["test"].executionTask.configure {
useJUnit()
}
withJava()
}
js(LEGACY) {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation("io.mockk:mockk:1.12.3")
}
}
val jvmMain by getting {
dependencies {
implementation("com.sparkjava:spark-core:2.9.3")
implementation("org.slf4j:slf4j-simple:2.0.0-alpha7")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.2")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
val exposedVersion: String by project
dependencies {
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
}
}
}
val jvmTest by getting {
}
val jsMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
// implementation("org.jetbrains.kotlin-wrappers:kotlin-react:17.0.2-pre.206-kotlin-1.5.10")
// implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:17.0.2-pre.206-kotlin-1.5.10")
}
}
val jsTest by getting {
}
}
}
application {
mainClass.set("GWServerKt")
}
tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack") {
outputFileName = "gw.js"
}
tasks.named<Copy>("jvmProcessResources") {
val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
from(jsBrowserDistribution)
}
tasks.named<JavaExec>("run") {
dependsOn(tasks.named<Jar>("jvmJar"))
classpath(tasks.named<Jar>("jvmJar"))
}