Skip to content

Make MinimalExternalModuleDependency#toString work #17882

@liutikas

Description

@liutikas

Consider:

fun getDependencyAsString(dependencyProvider: Provider<MinimalExternalModuleDependency>): String {
    val dependency = dependencyProvider.get()
    return dependency.module.toString() + ":" + dependency.versionConstraint.toString()
}

fun Project.createConfiguration(): FileCollection { 
    val configuration = configurations.findByName("metalava") ?: configurations.create("metalava") {
        val libs = project.extensions.getByType(
            VersionCatalogsExtension::class.java
        ).find("libs").get()
        val dependency = dependencies.create(
            getDependencyAsString(libs.findDependency("metalava").get())
        )
        it.dependencies.add(dependency)
    }
    return project.files(configuration)

and gradle/libs.versions.toml

[libraries]
metalava = { module = "com.android.tools.metalava:metalava", version = "1.0.0-alpha04" }

Expected Behavior

MinimalExternalModuleDependency.toString() returns com.android.tools.metalava:metalava:1.0.0-alpha04

Current Behavior

MinimalExternalModuleDependency.toString() returns org.gradle.api.internal.artifacts.dependencies.DefaultMinimalDependency@5e055771, so we have to write our own getDependencyAsString function.

Context

It is very common to need string representation of a dependency and thus it should work out of the box or at least have getAsString() type method.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions