Giter VIP home page Giter VIP logo

versioncategorysample's Introduction

Sample

(1) Import from Version Catalogs

// root/dependencies.gradle

ext {
    // version category로부터 취득
    core = libs.versions.core.get()
    println ">>> Core version : " + core

    // Library 항목들도 category로부터 취득
    def libsFromToml = extensions.getByType(VersionCatalogsExtension).named("libs")
    def librariesValue = [:]
    libsFromToml.libraryAliases.each {
        librariesValue[it] = getLibraryByName(libsFromToml, it)
    }
    libraries = librariesValue
    // check
    println ">>> Libraries in Version Category"
    libraries.each { key, value ->
        println "[${key}] : ${value}"
    }
}

private getLibraryByName(VersionCatalog libs, String name) {
    def library = libs.findLibrary(name)
    if (library.isPresent()) {
        return library.get().get()
    } else {
        throw GradleException("Could not find a library for `$name`")
    }
}

Result

>>> Core version : 1.9.0
>>> Libraries in Version Category
[activity] : androidx.activity:activity-ktx:1.6.0
[androidX.appcompat] : androidx.appcompat:appcompat:1.5.1
[androidX.core] : androidx.core:core:1.9.0
[google.material] : com.google.android.material:material:1.6.1

(2) Use Extra Properties

// app/build.gradle

dependencies {
    def ext = rootProject.ext
    // Use version in ExtraPropertiesExtension <-- from Version Category
    implementation "androidx.core:core-ktx:${ext.core}"
    // Use library in ExtraPropertiesExtension <-- from Version Category
    implementation ext.libraries.activity

    // Use library in Version Category
    implementation libs.google.material
}

versioncategorysample's People

Contributors

pluu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.