morteza mgh
morteza mgh

Reputation: 33

exclude a library in dependencies block of apply function in Plugin class

I use build-logic package as Gradle Convention Plugin and version catalog in my android modular project,

In one of my Plugin in build-logic package, as my plugin code is :

class MyConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            pluginManager.apply {
                apply("...")
                apply("...")
            }

            dependencies {
                add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
            }
        }
    }
}

I want to exclude a library in dependencies block of apply function in Plugin class or version catalog file, Is there any way to exclude a library from dependencies of androidx.hilt.navigation.compose here?

like what we can do in KotlinDslGradle of each module with implementation function as following:

implementation(libs.androidx.hilt.navigation.compose) {
        exclude(group = "androidx.navigation", module = "navigation-runtime") 
}

B.T.W, I tried snippet code above in KotlinDslGradle of app module and it didn't work.

Upvotes: 0

Views: 27

Answers (1)

Simon Jacobs
Simon Jacobs

Reputation: 6588

You can do the following:

with(target) {
    val libs = the<VersionCatalogsExtension>().named("libs")
    dependencies {
        addProvider<MinimalExternalModuleDependency, MinimalExternalModuleDependency>(
            "implementation",
            libs.findLibrary("androidx.hilt.navigation.compose").get()
        ) {
            exclude(group = "androidx.navigation", module = "navigation-runtime")
        }
    }
}

Upvotes: 1

Related Questions