Gradle Kotlin构建脚本无法获取SpringBoot库

时间:2019-06-21 04:03:40

标签: build.gradle gradle-kotlin-dsl

我在构建脚本上尝试了几种方法,但是仍然无法将springboot lib放入我的jar中,我可以知道下面的脚本出了什么问题吗?

父级Gradle Kotlin DSL

import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

extra["kotlin.version"] = "1.3.31"

plugins {
    java
    idea
    id("org.springframework.boot") version "2.1.4.RELEASE" apply false
    kotlin("jvm") version "1.3.31" apply false
    kotlin("plugin.spring") version "1.3.31" apply false
}

subprojects {
    apply(plugin = "org.jetbrains.kotlin.jvm")
    apply(plugin = "org.jetbrains.kotlin.plugin.spring")

    apply(plugin = "io.spring.dependency-management")

    the<DependencyManagementExtension>().apply {
        imports {
            mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
        }
    }

    group = "com.company.market"
    version = System.getenv("VERSION") ?: "0.2-SNAPSHOT"

    java {
        sourceCompatibility = JavaVersion.VERSION_1_8
    }

    repositories {
        maven {
            credentials {
                username = "anonymous"
                password = "anonymous"
            }
            url = uri("http://repo1.maven.apache.org/maven2/")
        }
    }

    dependencies {
        implementation(kotlin("reflect"))
        implementation(kotlin("stdlib-jdk8"))
        testImplementation("org.springframework.boot:spring-boot-starter-test")
    }

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

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

儿童(API)Gradle Kotlin DSL

这是将用于部署的子模块

plugins {
    `java`
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE")
    implementation("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.4.RELEASE")
    implementation("org.springframework.boot:spring-boot-devtools")
    implementation("org.apache.commons:commons-dbcp2")
    implementation("org.mariadb.jdbc:mariadb-java-client")
    implementation("org.springframework.boot:spring-boot-loader:2.1.4.RELEASE")
    implementation(project(":app-expr"))
    implementation(project(":app-data"))
}

我可以成功构建api模块,但是jar很小,并且意识到lib不是在jar中构建的。

1 个答案:

答案 0 :(得分:0)

我在子项目中添加了springboot lib并解决了

plugins {
    `java`
    id("org.springframework.boot")
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE")
    implementation("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.4.RELEASE")
    implementation("org.springframework.boot:spring-boot-devtools")
    implementation("org.apache.commons:commons-dbcp2")
    implementation("org.mariadb.jdbc:mariadb-java-client")
    implementation("org.springframework.boot:spring-boot-loader:2.1.4.RELEASE")
    implementation(project(":expr"))
    implementation(project(":data"))
}