基于kotlin的多模块项目设置中的gradle依赖性失败

时间:2018-02-23 11:12:29

标签: gradle kotlin spring-boot-gradle-plugin

我有一个基于gradle脚本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")
    }

0 个答案:

没有答案