jar + proguard in gradle



  • I have a project with the librarians. At one beautiful moment, I decided to connect ProGuard to him. As I realized, giving ProGuard to jar with all the dependent libraries inside isn't very cool.

    I decided to go this way:

    1. Get my classes in jar.
    2. Give ProGuard'u jar from the previous paragraph.
    3. The result is to leak to all dependent libraries.

    Now in gradle.build:

    group 'Alex_P'
    version '3.0.0-PRE'
    

    apply plugin: 'java'
    apply plugin: 'idea'

    sourceCompatibility = 1.8

    repositories {
    mavenCentral()
    }

    buildscript {
    repositories {
    flatDir dirs: '.'
    }
    dependencies {
    classpath ':proguard:'
    }
    }

    task assembleSingleJar(type: Jar) {
    manifest {
    attributes 'Implementation-Title': project.name,
    'Implementation-Version': version,
    'Main-Class': 'ru.alexp.gc.FileManager'
    }
    baseName = project.name + '-all'
    from {
    configurations.compile.collect {
    it.isDirectory() ? it : zipTree(it)
    }
    }
    with jar
    }

    jar {
    manifest {
    attributes 'Implementation-Title': project.name,
    'Implementation-Version': version,
    'Main-Class': "ru.alexp.gc.FileManager"
    }
    }

    task proguard(type: proguard.gradle.ProGuardTask) {
    configuration 'proguard.cfg'

    injars 'build/libs/FileManager-all-3.0.0-PRE.jar'
    outjars 'build/libs/FileManager-all-3.0.0-PRE-PRO.jar'
    

    }

    dependencies {
    compile 'org.json:json:20151123'
    compile 'org.apache.logging.log4j:log4j-api:2.4.1'
    compile 'org.apache.logging.log4j:log4j-core:2.4.1'

    testCompile group: 'junit', name: 'junit', version: '4.11'
    

    }



  • giving ProGuard to jar with all the dependent libraries inside isn't really cool.

    I think it's best to give him jar with dependent libraries. Then the file gets more streamlined - smaller.

    ProGuard reduces the size of the file by changing classes/methods/fields. Like, class. MyClass steel a♪ Give him the dependent libraries, he'll change their class too.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2