简体   繁体   English

子项目中添加的依赖项在gradle多模块kotlin DSL中的子项目中,每个子项目都不可见

[英]dependencies added in subprojects.forEach in gradle multi-module kotlin DSL is not visible to sub projects

I have multi-module gradle project with kotlin dsl called stream-data-processing. 我有一个带有kotlin dsl的多模块gradle项目,称为流数据处理。 It is in github here . 它在github 这里

The build.gradle.kts file of root project is - 根项目的build.gradle.kts文件是 -

    plugins {
        base
        java
    }

    allprojects {

        group = "streams-data-processing"
        version = "1.0"

        repositories {
            jcenter()
            mavenCentral()
            mavenLocal()
        }

        dependencies {
            subprojects.forEach {
                compile("org.apache.kafka:kafka-streams:2.2.0")

                testImplementation("junit:junit:4.12")
            }
        }

    }

settings.gradle.kts is - settings.gradle.kts是 -

   rootProject.name = "stream-data-processing"
   include ("word-count-demo")

I have some sub-project called word-count-demo . 我有一些名为word-count-demo子项目。

The build.gradle.kts file for this sub project is - 此子项目的build.gradle.kts文件是 -

    plugins {
        java

        application
    }

But the classes in kafka-streams are not available in word-count-demo . 但是kafka-streams中的类在word-count-demo中不可用。

想法编译错误

when I did `gradle word-count-demo:dependencies, it doesn't show the kafka dependencies available to the sub project. 当我做`gradle word-count-demo:dependencies时,它没有显示子项目可用的kafka依赖项。

I don't want to explicitly specify the dependencies in every project. 我不想在每个项目中明确指定依赖项。

What is the mistake that went wrong here? 这里出错的错误是什么?

It appears this would be adding the same dependencies multiple times. 看起来这将是多次添加相同的依赖项。 I think you need to flip it around and call dependencies inside subprojects , and outside of allprojects , like so: 我认为你需要翻转它并在subprojects调用dependencies ,并在所有subprojects 之外 allprojects ,如下所示:

allprojects {
    group ...
    version ...
    repositories ...
}

subprojects {
    dependencies {
        compile("org.apache.kafka:kafka-streams:2.2.0")
        testImplementation("junit:junit:4.12")
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将多模块 gradle 脚本转换为 kotlin dsl 时遇到问题 - Trouble converting multi-module gradle script to kotlin dsl gradle kotlin dsl - 如何为子项目配置依赖 - gradle kotlin dsl - How to configure dependencies for subprojects Gradle插件可以修改多模块项目中的子项目列表吗? - Can a Gradle plugin modify the list of subprojects in a multi-module project? 如何在 Kotlin DSL 中为多模块项目创建“基础”gradle 文件? - How to create a "base" gradle file in Kotlin DSL for multi-module project? maven多模块项目如何包括gradle子项目? - How can a maven multi-module project include gradle sub-projects? Gradle 多模块项目编译失败,来自子模块中提到的依赖项的“classNotFoundExceptions” - Gradle multi-module project compilation fails with "classNotFoundExceptions" from dependencies mentioned in sub-modules Intellij无法从Gradle多模块项目生成模块依赖项 - Intellij not generating module dependencies from Gradle multi-module project Gradle Kotlin DSL:子项目和插件的问题 - Gradle Kotlin DSL: Problems with subprojects and plugins 多项目 Gradle+Kotlin:如何使用 Kotlin DSL 创建包含所有子项目的 Jar? - Multi-project Gradle+Kotlin: How to create Jar containing all sub-projects using Kotlin DSL? 在多模块 Gradle 构建中从根访问子模块依赖项 - Access submodule dependencies from root in multi-module Gradle build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM