【问题标题】:Spring Boot Gradle dependencies in Kotlin MultiplatformKotlin Multiplatform 中的 Spring Boot Gradle 依赖项
【发布时间】:2020-02-13 13:13:00
【问题描述】:

我有一个 Kotlin 多平台项目,我正在尝试将 Spring Boot 添加到我的 Gradle 依赖项中。当从Spring Initializr 生成项目时,它会创建developmentOnly 依赖配置,如下所示。它还创建testImplementation 依赖配置。

下面的第一个build.gradle.kts 是我尝试将这些转移到一个多平台项目,到目前为止还没有奏效。我已经标记了 cmets 有问题的行,它们位于文件的底部。之后,我放了一个普通的 Spring Boot build.gradle.kts 进行对比。

如何将它们放入多平台项目中?或者,如果由于某种原因无法添加它们,请以达到相同结果的方式设置配置。

plugins {
    id("org.springframework.boot") version "2.2.4.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    kotlin("multiplatform") version "1.3.70-eap-184"
    kotlin("plugin.spring") version "1.3.70-eap-184"
    kotlin("plugin.jpa") version "1.3.70-eap-184"
}

group = "com.test"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_13
java.targetCompatibility = JavaVersion.VERSION_13

repositories {
    maven { url = uri("https://dl.bintray.com/kotlin/kotlin-dev/") }
    maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
    maven { url = uri("https://kotlin.bintray.com/kotlinx") }
    maven { url = uri("https://dl.bintray.com/kotlin/kotlin-js-wrappers") }
    mavenCentral()
    jcenter()
}

kotlin {
    jvm()
    js {
        browser()
    }
}

kotlin.sourceSets["jsMain"].dependencies {
    implementation(kotlin("stdlib-js"))

    implementation("org.jetbrains:kotlin-react:16.9.0-pre.91-kotlin-1.3.61")
    implementation("org.jetbrains:kotlin-react-dom:16.9.0-pre.91-kotlin-1.3.61")
    implementation(npm("react", "16.12.0"))
    implementation(npm("react-dom", "16.12.0"))

    implementation("org.jetbrains:kotlin-styled:1.0.0-pre.91-kotlin-1.3.61")
    implementation(npm("styled-components", "5.0.1"))
    implementation(npm("inline-style-prefixer", "5.1.1"))


    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3")
}

//The problems begin here
val developmentOnly by configurations.creating
configurations {
    runtimeClasspath { //can't resolve runtimeClasspath
        extendsFrom(developmentOnly) //can't resolve extendsFrom
    }
}

kotlin.sourceSets["jvmMain"].dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
    implementation("org.springframework.boot:spring-boot-starter-security")
    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.springframework.session:spring-session-core")
    developmentOnly("org.springframework.boot:spring-boot-devtools") //error because of above where developmentOnly is defined
    runtimeOnly("org.postgresql:postgresql")
    testImplementation("org.springframework.boot:spring-boot-starter-test") { //can't resolve testImplementation
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.springframework.security:spring-security-test") //can't resolve testImplementation

}

普通 build.gradle.kts 使用 Spring Boot(没有问题)

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

group = "com.test"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

val developmentOnly by configurations.creating
configurations {
    runtimeClasspath {
        extendsFrom(developmentOnly)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    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")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    runtimeOnly("com.microsoft.sqlserver:mssql-jdbc")
    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")
    }
}

【问题讨论】:

    标签: spring-boot gradle kotlin


    【解决方案1】:

    我能够完成所有设置。我做了一个starter project,以防其他人需要做同样的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-17
      • 2021-09-08
      • 2020-03-31
      • 2019-07-26
      • 1970-01-01
      • 2020-12-08
      • 2015-06-28
      • 2018-01-31
      相关资源
      最近更新 更多