Giter VIP home page Giter VIP logo

versioncontroldemo's Introduction

buildSrc 的缺陷

Android 开发中统一不同 module 的依赖版本十分重要,传统的方式是使用 ext 的方式

ext

之前我发过关于使用 buildSrc 简化项目中 gradle 代码的译文:什么?项目里gradle代码超过200行了!你可能需要 Kotlin+buildSrc Plugin

该种方式可以很好的管理 gradle 的公共配置,这其中当然包括依赖版本

配置依赖

如图,在使用依赖时有代码提示,而且可以点击进入查看

但是由于 buildSrc 是对全局的所有 module 的配置,因此在构建速度上会慢一些。那么有没有一个更纯净的方式来配置依赖版本呢?

今天我们来介绍一种新的方式

自定义 plugin + includeBuild

使用 Gradle Composite builds 可以很容易解决这一问题

我们新建一个 module,命名为 version ,并将原来的 buildSrc 的代码转移过来

class DependencyVersionPlugin : Plugin<Project> {
    override fun apply(project: Project) {

    }
}

在 version 的 build.gradle 文件加入

gradlePlugin {
    plugins {
        version {
            id = 'com.flywith24.version'
            implementationClass = 'com.flywith24.version.DependencyVersionPlugin'
        }
    }
}

在 settings.gradle 加入 includeBuild("version")重点

includeBuild("version")

rootProject.name='VersionControlDemo'
include ':app'
include ':lib'

接下来在需要引用的 module 中引入该插件

plugins {
    id "com.flywith24.version"
}

之后我们就可以使用了

往期文章

该系列主要介绍一些「*操作」,它未必适合生产环境使用,但是是一些比较新颖的思路

我的其他系列文章 在这里

关于我

我是 Fly_with24

versioncontroldemo's People

Contributors

flywith24 avatar

Watchers

 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.