首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子模块项目不能作为依赖项向消费者提供- Kotlin Gradle DSL

子模块项目不能作为依赖项向消费者提供- Kotlin Gradle DSL
EN

Stack Overflow用户
提问于 2022-06-08 12:56:06
回答 1查看 141关注 0票数 1

所以我有一个多模块的项目,错误处理。其中我有一个公共库,其中包含我发布的库所使用的一些类,但我也想向使用者公开整个库。这是一个结构:

代码语言:javascript
复制
 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

代码语言:javascript
复制
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

代码语言:javascript
复制
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依赖,我无法完成任务。知道为什么会这样吗?

EN

回答 1

Stack Overflow用户

发布于 2022-06-08 13:54:01

api(project(...))是不够的,您还需要实际发布其他项目。

api只是意味着使用者不需要显式地添加对另一个模块的依赖,但是它仍然需要存在于maven存储库中。

另一种选择是手动将公共模块中的所有编译文件添加到库的jar中,但如果只独立发布公共模块,这是很麻烦的,不应该是必需的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72546087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档