intellij-idea - 子项目中对包的未解决依赖关系

标签 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

它提示的实际线路是:
import com.path.database.repositories.UsersRepository
it错误是来自 repo 的值。 UserRepository类(class)在模块 database 中和 JwtRealmsecurity模块。

我的 build.gradle.kts security 中的文件模块如下所示:
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

关于intellij-idea - 子项目中对包的未解决依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53775262/

相关文章:

安卓工作室 : How to add end/closing tag automatically in layout xml file

android - 如何在 Firebase 中存储 BigDecimal?

java - Gradle 构建在 :compileJava: `No matching variant` 处失败

android - 如何在 Kotlin 中抛出 HttpException - 改造 2 - 单元测试

安卓相机2 API。设置多个 ImageReader 表面会产生空白输出

android - 无法从代码中引用生成的资源

gradle - Kotlin DSL : Import a versions. gradle.kts 进入另一个 build.gradle.kts

encoding - Android Studio 将 BOM 写入 UTF-8 文件

intellij-idea - 无法将 Groovy SDK 添加到 Intellij

css - IntelliJ gwt 插件 - 为什么我会收到 "unknown css class"错误?