Я не могу понять, как заставить зависимость commonMain работать в многоплатформенном проекте kotlin. Я прочитал и перечитал документацию много раз и просмотрел множество примеров, но это просто не работает. Вот самый маленький пример, который, я считаю, должен работать. Что я делаю не так?
multiplatform-lib
plugins {
kotlin("multiplatform") version "1.3.61"
`maven-publish`
}
group = "github.fatalcatharsis"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
mavenLocal()
}
kotlin {
/* Targets configuration omitted.
* To find out how to configure the targets, please follow the link:
* https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets */
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
}
}
src / commonMain / kotlin / Test.kt
data class Test (
val test : Int
)
multiplatform-test
plugins {
kotlin("multiplatform") version "1.3.61"
}
group = "github.fatalcatharsis"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
mavenLocal()
}
kotlin {
/* Targets configuration omitted.
* To find out how to configure the targets, please follow the link:
* https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#setting-up-targets */
js {
browser()
}
jvm()
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation("github.fatalcatharsis:multiplatform-lib-metadata:1.0-SNAPSHOT")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
}
}
src / commonMain / kotlin / Tester.kt
import github.fatalcatharsis.Test
fun test() {
val meh = Test()
}
intellij говорит, что разрешает зависимость в меню проекта очень хорошо, но выделяет github красным. Автозаполнение недоступно для «Тест». Ошибки с multiplatform-test\src\commonMain\kotlin\Tester.kt: (1, 8): Unresolved reference: github
. Похоже, что контент зависимостей недоступен в commonMain. Я чувствую, что пропустил что-то тонкое и очевидное. Любые идеи?
Редактировать : Делая обратное тому, что документация говорит для общих зависимостей, если я изменяю зависимость на:
implementation("github.fatalcatharsis:multiplatform-lib:1.0-SNAPSHOT")
, это выдает ошибку:
Could not determine the dependencies of task ':jsPackageJson'.
> Could not resolve all dependencies for configuration ':jsNpm'.
> Could not resolve github.fatalcatharsis:multiplatform-lib:1.0-SNAPSHOT.
Required by:
project :
> Unable to find a matching variant of github.fatalcatharsis:multiplatform-lib:1.0-SNAPSHOT:
- Variant 'metadata-api':
- Found org.gradle.status 'integration' but wasn't required.
- Required org.gradle.usage 'kotlin-runtime' and found incompatible value 'kotlin-api'.
- Required org.jetbrains.kotlin.platform.type 'js' and found incompatible value 'common'.