Search code examples
gradlebuild.gradletoml

Gradle Version Catalog specify library build type


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?


Solution

  • 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'
            }
        }
    
    }