Gradle Version Catalog specify library build type
Asked Answered
G

1

13

I'm refactoring a multi module project with version catalogs and I have to add a dependency that is currently like this:

implementation com.mygroup:my-artifact:1.0.0:debug@aar

Since version catalogs doesn't allow to specify the aar type, a workaround would be to specify it directly in the gradle file like this:

implementation(libs.myDependency) { artifact { type = 'aar' } }

This works, but there's an extra complexity: I need to also specify the build type, in the example from above is debug, I cannot find a way to add it.

What I've tried is:

TOML

[libraries]
myDependency = { module = "com.mygroup:my-artifact", version = "1.0.0:debug" }

Gradle

implementation(libs.myDependency) { artifact { type = 'aar' } }

For some reason this doesn't work, how can I also specify the build type?

Ghent answered 3/9, 2021 at 14:7 Comment(0)
G
23

Found a way to do this! Need to add the classifier into the artifact.

So for the given regular declaration:

build.gradle

dependencies {
    implementation com.mygroup:my-artifact:1.0.0:debug@aar
}

The version catalogs way would be:

TOML

[libraries]
myDependency = { module = "com.mygroup:my-artifact", version = "1.0.0" }

build.gradle

dependencies {
    implementation(libs.myDependency) {
        artifact {
            classifier = 'debug'
            type = 'aar'
        }
    }

}
Ghent answered 3/9, 2021 at 14:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.