flat-aar 和 flat-jar

flat-aar

https://github.com/kezong/fat-aar-android

flat-jar

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
    implementation 'io.netty:netty-all:4.1.67.Final'
}

group 'org.greenleaf'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

jar {
    manifest {
        attributes "Main-Class": "org.greenleaf.Application"
    }

    archiveBaseName = 'flat-jar'

    from {
       configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

task customFatJar(type: Jar) {
    manifest {
        attributes "Main-Class": "org.greenleaf.Application"
    }
    archiveBaseName = 'flat-jar-custom'
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

推荐

https://github.com/johnrengelman/shadow

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.github.jengelman.gradle.plugins:shadow:5.2.0"
    }
}

apply plugin: "com.github.johnrengelman.shadow"
apply plugin: 'java'

// 构建可执行 jar 包,运行依赖jar内容会直接打到 jar 里面
shadowJar {
    // 生成包的命名规则: baseName-version-classifier.jar
    archiveClassifier = 'flat-jar'
    manifest {
        attributes(
                'Main-Class': 'org.greenleaf.Applicationn'
        )
    }

    // 排除配置文件
    exclude('system.properties')
    exclude('pom.xml')

    // 将 build.gradle 打入到 jar 中, 方便查看依赖包版本
    from("./") {
        include 'build.gradle'
    }
}

你可能感兴趣的:(flat-aar 和 flat-jar)