Unresolved Dependency on package in subproject

…衆ロ難τιáo~ 提交于 2020-07-07 04:28:24

问题


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

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

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

The actual line it is complaining about is:

import com.path.database.repositories.UsersRepository

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

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")
}

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 has no problem running, or browsing this code, there are no highlighted errors or warnings.

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

What am I missing?


回答1:


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

to each of the subprojects. In KotlinDSL this is:

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

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



来源:https://stackoverflow.com/questions/53775262/unresolved-dependency-on-package-in-subproject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!