[英]Sub module project is not available for consumers as a dependency - Kotlin Gradle DSL
So I have a multi-module project, error-handling.所以我有一个多模块项目,错误处理。 Where I have a common lib that contains some classes that are used by the lib that I publish, but also I would like to expose that entire lib to the consumers.
我有一个公共库,其中包含我发布的库使用的一些类,但我也想将整个库公开给消费者。 This is the structure:
这是结构:
Example:
error-handling-lib ## root
├── error-handling-common ## Common lib, compiled to JS/JVM
│ └─── build.gradle.kts
│
├── error-handling-lib-jvm ## JVM specific lib
│ └── error-handling-lib-ktor ## KTOR specific - !final!
│ │
│ └── build.gradle.kts ## Build all framework-specific versions
error-handling-common has the following build.gradle.kts
error-handling-common 有以下
build.gradle.kts
plugins {
id ("java-library")
kotlin("jvm") version "1.6.20"
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
id("org.jlleitschuh.gradle.ktlint-idea") version "10.2.1"
}
repositories {
mavenCentral()
}
dependencies {
// CORE
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
// TEST DEPENDENCIES
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
// KOTEST
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-json:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-json:$kotestVersion")
testImplementation("io.kotest.extensions:kotest-assertions-ktor:$kotestKtorAssertionVersion")
testImplementation("io.kotest.extensions:kotest-extensions-koin:$kotestKoinExtVersion")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
}
error-handling-lib-ktor错误处理库-ktor
plugins {
id("java-library")
kotlin("jvm") version "1.6.20"
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
id("org.jlleitschuh.gradle.ktlint-idea") version "10.2.1"
id("maven-publish")
id("com.google.cloud.artifactregistry.gradle-plugin") version "2.1.5"
}
repositories {
mavenCentral()
maven {
url = uri("artifactregistry://......./maven-app-libraries")
}
}
dependencies {
// CORE
api(project(":error-handling-common"))
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-server-auto-head-response:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
implementation("io.ktor:ktor-server-cors:$ktorVersion")
implementation("io.ktor:ktor-server-call-logging:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
// TESTS
testImplementation("io.insert-koin:koin-test:$koinVersion")
testImplementation("io.ktor:ktor-server-netty:$ktorVersion")
testImplementation("io.ktor:ktor-server-tests:$ktorVersion")
testImplementation("io.ktor:ktor-server-test-host:$ktorVersion")
// TEST DEPENDENCIES
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
// KOTEST
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-json:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-core:$kotestVersion")
testImplementation("io.kotest:kotest-assertions-json:$kotestVersion")
testImplementation("io.kotest.extensions:kotest-assertions-ktor:$kotestKtorAssertionVersion")
testImplementation("io.kotest.extensions:kotest-extensions-koin:$kotestKoinExtVersion")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
}
Unfortunately with the API dependency, I'm not getting the job done.不幸的是,由于 API 依赖,我没有完成工作。 Any ideas why this is happening?
任何想法为什么会发生这种情况?
api(project(...))
is not sufficient, you also need to actually publish that other project. api(project(...))
是不够的,您还需要实际发布该其他项目。
api
just means that consumers won't need to explicitly add a dependency on that other module, but it still needs to exist in the maven repository. api
只是意味着消费者不需要显式添加对该其他模块的依赖,但它仍然需要存在于 maven 存储库中。
Another option would be to manually add all the compiled files from the common module into the library's jar, but that is hacky and shouldn't be necessary if you just publish the common module independently.另一种选择是将公共模块中的所有已编译文件手动添加到库的 jar 中,但这是 hacky 并且如果您只是独立发布公共模块则不需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.