https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

Nicholas Bilyk

08/23/2019, 5:43 PM
I'm kind of stuck on another Kotlin Gradle question. I am trying to create a Gradle configuration for a jvm classpath, but I'm getting an AmbiguousConfigurationSelectionException. In java this works:
Copy code
configurations.create("myConfig") {
	dependencies.apply {
		add(project.dependencies.create("com.example:foo:version"))
	}
}

// In the task:
getExecActionFactory().newJavaExecAction().apply {
	classpath = project.configurations.getByName("myConfig")
}
But I don't know how to do the equivalent if the dependency is a kotlin multi-platform library. I get an exception such as:
Copy code
Caused by: org.gradle.internal.component.AmbiguousConfigurationSelectionException: Cannot choose between the following variants of com.example:foo:version:
  - js-api
  - js-runtime
  - jvm-api
  - jvm-runtime
  - metadata-api
I'm very shaky on this, but here's what I ended up doing that seems to work... Advice on improvements are welcome.
Copy code
packTexturesCompilation = kotlinExt.targets.getByName("jvm").compilations.create("packTextures") {
		dependencies {
			runtimeOnly("com.acornui:acornui-texture-packer:$acornVersion")
		}
	} as KotlinCompilationToRunnableFiles<KotlinCommonOptions>
Copy code
getExecActionFactory().newJavaExecAction().apply {
					main = "com.acornui.texturepacker.PackAssetsKt"
					args = listOf(it.sourceDir.absolutePath, it.destinationDir.parentFile.absolutePath, suffix)
					classpath = packTexturesCompilation.runtimeDependencyFiles
					execute()
				}
2 Views