0

我有一个基于 gradle script kotlin 的多模块 gradle 项目设置。看来我搞砸了项目的依赖管理,但我找不到问题所在。每当我添加新的依赖项并运行gradle build构建本身时,它都会成功,但无法将依赖项添加到项目中。为了分析我运行的问题gradle dependencies,我可以看到它无法检索依赖项,如下所示:

> Task :dependencies

    ------------------------------------------------------------
    Root project
    ------------------------------------------------------------

    archives - Configuration for archive artifacts.
    \--- project :nanoservices-web-api
     +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.21
     |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.2.21
     |    |    \--- org.jetbrains:annotations:13.0
     |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.21
     |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.21 (*)
     +--- org.jetbrains.kotlin:kotlin-reflect:1.2.21
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.21 (*)
     +--- org.springframework.boot:spring-boot-starter-web: FAILED
     +--- org.springframework.boot:spring-boot-starter-actuator: FAILED
     +--- org.springframework.boot:spring-boot-starter-data-jpa: FAILED
     +--- org.springframework.boot:spring-boot-starter-cache: FAILED
     +--- javax.cache:cache-api: FAILED
     +--- com.h2database:h2: FAILED
     \--- com.fasterxml.jackson.module:jackson-module-kotlin: FAILED

    default - Configuration for default artifacts.
    No dependencies

我使用的 gradle 版本是 5.4.1 谁能发现我犯的错误?
您可以在下面找到构建文件。这是顶级 build.gradle.kts 文件:

allprojects {
    group = "localhost.playground"
    version = "1.0-SNAPSHOT"

    repositories {
        mavenCentral()
    }
}

plugins {
    base
}

dependencies {
// Make the root project archives configuration depend on every subproject
    subprojects.forEach {
        archives(it)
    }
}

以下是目前唯一的子项目。

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

buildscript {

    extra["kotlinVersion"] = "1.2.21"
    extra["springBootVersion"] = "1.5.10.RELEASE"

    val springBootVersion: String by extra
    val kotlinVersion: String by extra

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
        classpath("org.junit.platform:junit-platform-gradle-plugin:1.1.0")
    }
}

val kotlinVersion: String by extra
val springBootVersion: String by extra

plugins {
    val kotlinVersion = "1.2.21"
    id("org.jetbrains.kotlin.jvm") version kotlinVersion
    id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
    id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
    id("io.spring.dependency-management") version "1.0.4.RELEASE"
}

apply {
    plugin("org.springframework.boot")
    plugin("org.junit.platform.gradle.plugin")
}

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

dependencies {
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
    compile("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-cache")
    compile("javax.cache:cache-api")
    compile("com.h2database:h2")
    compile("com.fasterxml.jackson.module:jackson-module-kotlin")

    testCompile("org.springframework.boot:spring-boot-starter-test") {
        exclude(module = "junit")
    }
    testCompile("org.junit.jupiter:junit-jupiter-api:5.1.0")
    testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.0")
    }
4

0 回答 0