Search code examples
gradlebuildmulti-module

Gradle multi-module project build problem


I have a multi-module project with following structure

enter image description here

When I try to build signal-site project I get this Exception

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all task dependencies for configuration ':runtimeClasspath'.

settings.gradle.kts (trade) - top level

rootProject.name = "trade"
include("trade-common")
include("signal-site")

build.gradle.kts (trade) - top level

group = "com.oleinikdi"
version = "1.0"

subprojects {
    version = "1.0"
}

allprojects {
    repositories {
        jcenter()
    }
}

settings.gradle.kts (trade-common)

rootProject.name = "trade-common"

build.gradle.kts (trade-common)

subprojects {
    version = "1.0"
}

plugins {
    kotlin("jvm") version "1.3.70"
}

group = "com.oleinikdi"
version = "1.0"

repositories {
    jcenter()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
}

tasks {
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
}

settings.gradle.kts (signal-site)

rootProject.name = "signal-site"
include("trade-common")

build.gradle.kts (signal-site)

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

subprojects {
    version = "1.0"
}

plugins {
    id("org.springframework.boot") version "2.2.5.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    war
    kotlin("jvm") version "1.3.70"
    kotlin("plugin.spring") version "1.3.70"
    kotlin("plugin.jpa") version "1.3.70"
}

group = "com.oleinik"
version = "1.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    jcenter()
}

dependencies {
    implementation(project(":trade-common"))

    providedRuntime("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-data-rest")
    implementation("org.springframework.boot:spring-boot-starter-jdbc")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.liquibase:liquibase-core")
//    runtimeOnly("org.postgresql:postgresql")
    implementation("org.postgresql:postgresql")

    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.springframework.security:spring-security-test")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

Solution

  • In a multi project build, there must be only one settings.gradle file at the root of the project.

    So your issue is caused by having multiple settings.gradle defined in your hierarchy, which means when running something in signal-site, Gradle is configured to look for trade-common as a subfolder of signal-site.

    Simply remove the trade-common and signal-site settings.gradle files, leaving only the one at the root.

    See the documentation to get a deeper understanding of Gradle settings.gradle files and how they work in multi project setups.