FatJar:适用于sdk多module打包和合并多个jar的gradle插件

Download

usage:

1.下载fatJar.gradle放置于project根目录

2.在project的build.gradle中添加依赖和配置:

apply from: 'fatJar.gradle'
buildscript {
    dependencies {
        classpath 'xyz.bboylin:FatJarPlugin:1.0.5'
    }
}

//可配置项
fatJarExt {
	//这里可配置需要打包的module名和需要加入的第三方jar绝对路径
    jarPaths = ["/github/okhttp.jar",
             "libtwo",
             "commonlib"]
    //配置需要添加assets的module名,没有可删掉此项
    assetsPaths = ["libtwo","commonlib"]
    //最后output的jar名
    output = "result.jar"
    //manifest中created-by的值
    owner = "your name or your organization"
    //manifest中version的值
    version = 'your sdk version'
    //只打debug包的话加上这句,只打release包的话不加
    isDebug = true
}

3.项目根目录下命令行执行gradlew fatJar即可。

注意:

如果你的module不在项目根目录下,比如D:\MyApplication\components\liboneD:\MyApplication\components\player\bdplayerD:\MyApplication是我的项目根目录,那你不能直接写"libone",要改为"components:libone",即module用相对路径。示例:

fatJarExt {
    jarPaths = ["/github/okhttp.jar"
             ,"libtwo",
             ,"commonlib"
             ,"components:libone"
             ,"components:player:bdplayer"]
    assetsPaths = ["libtwo"
                    ,"components:libone"
                    ,"components:player:bdplayer"]
    //最后output的jar名
    output = "result.jar"
    //manifest中created-by的值
    owner = "your name or your organization"
    //manifest中version的值
    version = 'your sdk version'
    //只打debug包的话加上这句,不加默认只打release包
    isDebug = true
}

示例

apply plugin: 'FatJarPlugin'

def ROOT_BUILD_PATH = project.buildDir.absolutePath
def JAR_NAME = "ParserEngine_${buildInfo.version}.jar"

def BUBBLE_ASSETS_PATH = "${rootProject.rootDir.absolutePath}/Engines/BubbleEngine/src/main/assets"
def CARD_PARSER_ASSETS_PATH = "${rootProject.rootDir.absolutePath}/Engines/CardEngine/src/main/assets"

def BUBBLE_ASSETS_FILES = ["sms_bubble_stable_ac.index", "sms_bubble_stable_others.index", "sms_bubble_stable_regex.db"]
def CARD_RULE_ASSETS_FILES = ["sms_card_stable_ac.index", "sms_card_stable_others.index", "sms_card_stable_regex.db"]
def CARD_PARSER_ASSETS_FILES = ["parser.dic", "parser.zip"]

def SDK_OUT_PATH = "${ROOT_BUILD_PATH}/sdk_out_temp"
def SDK_ZIP_NAME = "parser_engine_${buildInfo.version}.zip"

def SO_PATH = "${rootProject.rootDir.absolutePath}/ParserEngine/src/main/jniLibs"

//依赖assembleDebug或者assembleRelease
fatJarTask.dependsOn({
    def tasks = new ArrayList<>()
    def taskName = fatJarExt.isDebug ? ":assembleDebug" : ":assembleRelease"
    fatJarExt.jarPaths.each {
        if (!it.contains(".jar")) {
            tasks.add(":" + it + taskName)
        }
    }
    return tasks.toArray()
})

//可配置项
fatJarExt {
    jarPaths = ["ParserEngine", "commonlib", "ActionLib"]
    output = JAR_NAME
    owner = "parserengine_${buildInfo.version}_${buildInfo.vcs_version}_${buildInfo.build_time}"
//    version = buildInfo.version
//    isDebug = true
}

task copySDK(type: Copy, dependsOn: [":fatJarTask"]) {
    delete JAR_NAME
    delete SDK_OUT_PATH
    delete "$ROOT_BUILD_PATH/$SDK_ZIP_NAME"

    into('/jniLibs') {
        from SO_PATH
    }
    into('/libs') {
        from JAR_NAME
    }
    into('/assets') {
        def allFiles = []
        allFiles.addAll(BUBBLE_ASSETS_FILES.collect { "${BUBBLE_ASSETS_PATH}/${it}" })
        allFiles.addAll(CARD_PARSER_ASSETS_FILES.collect { "${CARD_PARSER_ASSETS_PATH}/${it}" })
        allFiles.addAll(CARD_RULE_ASSETS_FILES.collect { "${CARD_PARSER_ASSETS_PATH}/${it}" })
        from allFiles
    }
    destinationDir(file(SDK_OUT_PATH))
}

task makeSDK(type: Zip, dependsOn: [copySDK]) {
    from SDK_OUT_PATH
    archiveName SDK_ZIP_NAME
    destinationDir(file(ROOT_BUILD_PATH))
}

转载于:https://my.oschina.net/sfshine/blog/2059235

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值