对子项目中的程序包的未解决依赖性 [英] Unresolved Dependency on package in subproject

查看:106
本文介绍了对子项目中的程序包的未解决依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my Kotlin spring boot project, I am using Kotlin DSL Gradle, with three subprojects. Two of which are security which depends on database.

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

In IntelliJ, the application runs successfully and performs as expected (when run as a Spring Boot application run config).

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

However, when I try to build the project with Gradle ./gradlew clean build I get

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中,而JwtRealmsecurity模块中.

The it error are values from the repo. The UserRepository class is in the module database and the JwtRealm is in the security module.

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

My build.gradle.kts file in the security module looks like this:

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

Which is basically the same as my root project Gradle files, only that also contains references to all the subprojects (or modules). I've also listed all the subprojects in the settings.gradle.kts

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

IntelliJ has no problem running, or browsing this code, there are no highlighted errors or warnings.

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

I have an @Configuration annotated class as the root of each module with @ComponentScan annotation also.

我想念什么?

推荐答案

经过大量挖掘,我发现这是Spring Boot问题.我通过应用

After a lot of digging I found that this was a Spring Boot issue. I fixed this by applying

bootJar.enabled = false  
jar.enabled = true

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

to each of the subprojects. In KotlinDSL this is:

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

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

I hope this helps someone else, as I only found this issue after a lot of digging. Source of the solution is here: https://github.com/gradle/kotlin-dsl/issues/393

这篇关于对子项目中的程序包的未解决依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆