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

Jum*_*wah 4 intellij-idea kotlin gradle-kotlin-dsl

在我的 Kotlin spring boot 项目中,我使用的是 Kotlin DSL Gradle,包含三个子项目。其中两个security取决于database.

在 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
Run Code Online (Sandbox Code Playgroud)

它抱怨的实际线路是:

import com.path.database.repositories.UsersRepository
Run Code Online (Sandbox Code Playgroud)

it错误是从回购值。本UserRepository类是模块中databaseJwtRealm是在security模块。

build.gradle.ktssecurity模块中的文件如下所示:

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")
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

我错过了什么?

Jum*_*wah 16

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

bootJar.enabled = false  
jar.enabled = true
Run Code Online (Sandbox Code Playgroud)

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

tasks.withType<BootJar> {
    enabled = false
}
tasks.withType<Jar> {
    enabled = true
}
Run Code Online (Sandbox Code Playgroud)

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