繁体   English   中英

对子项目中包的未解决依赖性

[英]Unresolved Dependency on package in subproject

在我的Kotlin春季启动项目中,我正在使用带有三个子项目的Kotlin DSL Gradle。 其中两个是依赖于database security

在IntelliJ中,应用程序成功运行并按预期运行(当以Spring Boot应用程序运行配置运行时)。

但是,当我尝试使用Gradle ./gradlew clean build项目时,我得到了

e: /security/src/main/kotlin/com/path/security/jwt/JwtRealm.kt: (3, 26): Unresolved reference: database
e: /security/src/main/kotlin/com/path/security/jwt/JwtRealm.kt: (19, 24): Unresolved reference: UsersRepository
e: /security/src/main/kotlin/com/path/security/jwt/JwtRealm.kt: (36, 48): Unresolved reference: it
e: /security/src/main/kotlin/com/path/security/jwt/JwtRealm.kt: (38, 42): Unresolved reference: it
e: /security/src/main/kotlin/com/path/security/jwt/JwtRealm.kt: (38, 75): Unresolved reference: it
e: /security/src/main/kotlin/com/path/security/jwt/JwtRealm.kt: (40, 63): Unresolved reference: it
> Task :security:compileKotlin FAILED

它抱怨的实际行是:

import com.path.database.repositories.UsersRepository

it错误是来自回购的值。 UserRepository类位于模块database ,而JwtRealm位于security模块中。

我在security模块中的build.gradle.kts文件如下所示:

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

group = "com.path"
version = "1.0-SNAPSHOT"

plugins {
    kotlin("jvm")
    id("org.jetbrains.kotlin.plugin.spring") 
    id("org.jetbrains.kotlin.plugin.noarg") 
    id("org.jetbrains.kotlin.plugin.jpa") 
    id("org.springframework.boot")
    id("io.spring.dependency-management")
}

repositories {
    mavenCentral()
}

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

    implementation(project(":database"))

    implementation("org.springframework.boot:spring-boot-starter-web:2.1.1.RELEASE")
    implementation("org.springframework.boot:spring-boot-starter-actuator:2.1.1.RELEASE")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.1.1.RELEASE")
    implementation("org.springframework.boot:spring-boot-starter-jdbc:2.1.1.RELEASE")

    implementation("org.apache.shiro:shiro-spring-boot-web-starter:1.4.0")
    implementation("com.h2database:h2:1.4.197")
    implementation("com.auth0:java-jwt:3.4.1")
    implementation("io.github.microutils:kotlin-logging:1.6.22")
}

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

这与我的根项目Gradle文件基本相同,只是它还包含对所有子项目(或模块)的引用。 我还在settings.gradle.kts列出了所有子项目

IntelliJ在运行或浏览此代码时没有问题,没有突出显示的错误或警告。

我有一个@Configuration注释的类作为每个带有@ComponentScan注释的模块的根。

我想念什么?

经过大量的挖掘,我发现这是一个Spring Boot问题。 我通过申请解决了这个问题

bootJar.enabled = false  
jar.enabled = true

到每个子项目。 在KotlinDSL中,这是:

tasks.withType<BootJar> {
    enabled = false
}
tasks.withType<Jar> {
    enabled = true
}

我希望这对其他人有帮助,因为我经过大量挖掘才发现了这个问题。 解决方案的来源在这里: https : //github.com/gradle/kotlin-dsl/issues/393

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM