所以我有一个多模块的项目,错误处理。其中我有一个公共库,其中包含我发布的库所使用的一些类,但我也想向使用者公开整个库。这是一个结构:
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错误处理-公共有以下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"
}
}错误处理-库-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"
}
}不幸的是,由于API依赖,我无法完成任务。知道为什么会这样吗?
发布于 2022-06-08 13:54:01
api(project(...))是不够的,您还需要实际发布其他项目。
api只是意味着使用者不需要显式地添加对另一个模块的依赖,但是它仍然需要存在于maven存储库中。
另一种选择是手动将公共模块中的所有编译文件添加到库的jar中,但如果只独立发布公共模块,这是很麻烦的,不应该是必需的。
https://stackoverflow.com/questions/72546087
复制相似问题