Search code examples
spring-bootkotlingradlebuild.gradlegradle-kotlin-dsl

How to access the dependency of a jar instead of writing the package names again the gradle kotlin?


Issue

Currently, I have a jar file as a common module for other spring boot applications which I would like to use for scanning.

app.build.gradle.kts

dependencies {
    api("com.company.app:appbase:0.0.1-SNAPSHOT")
}

I was not able to use the dependencies of the com.company.app.appbase, other than the base package itself, which shows errors like Unresolved reference: springframework

base-package.build.gradle.kts

dependencies{
   implementation("io.github.microutils:kotlin-logging:3.0.5")
   ... // Spring boot dependencies
}

How could I use the dependencies, e.g. io.github.microutils:kotlin-logging without importing it in app.build.gradle.kts?

Thank you.


Attempts

I have tried using implementation and api commands in the app.build.gradle.kts file but the results are the same.


Solution

  • It seems that you want transitive dependencies access, in this case you need to do the modifications not in the app.build.gradle.kts but in your com.company.app.appbase build script build.gradle.kts:

    dependencies {
        api("io.github.microutils:kotlin-logging:3.0.5")
    }
    

    Then by doing in the app.build.gradle.kts:

    dependencies {
        implementation("com.company.app:appbase:0.0.1-SNAPSHOT")
    }
    

    microutils should be then available without mentioning it.

    Check doc: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation