简体   繁体   中英

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. It is in github here .

The build.gradle.kts file of root project is -

    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 -

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

I have some sub-project called word-count-demo .

The build.gradle.kts file for this sub project is -

    plugins {
        java

        application
    }

But the classes in kafka-streams are not available in word-count-demo .

想法编译错误

when I did `gradle word-count-demo:dependencies, it doesn't show the kafka dependencies available to the sub project.

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM