A gradle plugin to optimize built jars through individual file optimizations and increased compression

Related tags

Plugin Machete
Overview

Machete

Machete is a gradle plugin that attempts to optimize the size of output JARs through both individual file optimizations and overall compression increases inspired by the Detonater project.

Simply applying the plugin should be enough to apply any optimizations in a standard environment, as it will collect output JARs that are known to be usable artifacts and optimize them after the build task.

Please note that this plugin works best on hgh-resource density projects. Code-heavy ones will have minimal success and may even inflate overall.

Optimizations

  • JSON files are minimized by reading+writing through a custom formatter, which strips any whitespace.
  • PNG files are run through the Oxipng project on maximum compression and metadata removal
  • Nested JAR files are unpacked and have the same optimizations run on them
  • XML files have extra whitespace removed
  • The final result is then compressed with DEFLATE level 9, providing modest overall compression (bytecode doesn't compress well unfortunately)

There are also some disabled-by-default optimizations as they are technically lossy on the behavior of the jar.

  • Local Variable Table stripping, disabled because this table is used for the "helpful NPEs" feature in java 14+
  • Source file stripping, disabled because this is used to give the file a class was compiled from in error messages

More optimizations are planned as well, feel free to open an issue!

Installation

Machete is available on the gradle plugin portal under io.github.p03w.machete, simply apply the plugin to your project, and it should work out of the box.

See here for in-depth install instructions.

Configuration

To configure the plugin, use the machete block. This allows you to

  • Add or remove tasks to pull output JARs from (additionalTasks/ignoredTasks, also please consider opening a PR if you use these)
  • Disable overwriting the original artifacts (keepOriginal)
  • Enable or disable specific optimizations (optimizations)

An example full config may look like:

machete {
    // Also optimize the output of task "foo"
    additionalTasks.add("foo")
    // Do not optimize the output of "bar"
    ignoredTasks.add("bar")
    
    // Keep the original copies in the build directory
    keepOriginal = true
    
    // Disable the JIJ, PNG, and JSON optimizations
    jij.enabled = false
    png.enabled = false
    json.enabled = false
    
    // Enable all lossy optimizations
    lvtStriping.enabled = true
    sourceFileStriping.enabled = true
    
    // Make the PNG optimization (even though disabled here, shush)
    // Use less optimization and no alpha optimizations
    png.alpha = false
    png.optimizationLevel = 2
}

To locate tasks that can be added, use the dumpTasksWithOutputJars task, that will automatically list any tasks with output JARs.

Supported 3rd party plugins

This is a list of currently supported 3rd party plugins that Machete can automatically optimize the output of. Please see KnownGoodTasks.kt for this support. If you are using a plugin that doesn't specify its output artifacts, I'm sorry, but I can't add support, please consider poking the developer about using that system (although im sure the code here is garbage as well LMAO, gradle have good docs challenge (impossible)).

You might also like...
A Gradle plugin to report the number of method references in your APK on every build.
A Gradle plugin to report the number of method references in your APK on every build.

Dexcount Gradle Plugin A Gradle plugin to report the number of method references in your APK, AAR, or java module. This helps you keep tabs on the gro

A Gradle plugin to support the Groovy language for building Android apps

Groovy language support for Android Deprecated: This plugin has been deprecated in favor of Kotlin which has the full support of JetBrains and Google.

Add a different ribbon to each of your Android app variants using this gradle plugin. Of course, configure it as you will

Easylauncher gradle plugin for Android Modify the launcher icon of each of your app-variants using simple gradle rules. Add ribbons of any color, over

A Gradle Plugin that removes unused resources in Android projects.
A Gradle Plugin that removes unused resources in Android projects.

#Lint Cleaner Plugin Removes unused resources reported by Android lint including strings, colors and dimensions. Depracated As of Android Studio 2.0+

Gradle plugin for Google Protocol Buffers

Gradle Protobuf Plugin Author: Andrew Kroh Download: See maven central License: Apache License, Version 2.0 Requirements: Java 1.5+ Google Protocol Bu

Gradle plugin which validates the licenses of your dependency graph match what you expect

Licensee 📜 👀 A Gradle plugin which validates the licenses of your dependency graph match what you expect, or it fails your build! Jump to: Introduct

IntelliJ plugin that provides some useful utilities to support the daily work with Gradle.
IntelliJ plugin that provides some useful utilities to support the daily work with Gradle.

IntelliJ Gradle Utilities Plugin This IntelliJ plugin provides some useful utilities to support the daily work with Gradle. It's available on the offi

Gradle plugin which helps you analyze the size of your Android apps.
Gradle plugin which helps you analyze the size of your Android apps.

Ruler Ruler is a Gradle plugin which helps you analyze the size of your Android apps. Motivation App size is an important metric which directly correl

A Gradle plugin for providing your secrets to your Android project.

Secrets Gradle Plugin for Android A Gradle plugin for providing your secrets securely to your Android project. This Gradle plugin reads secrets from a

Comments
  • Cannot find Oxipng

    Cannot find Oxipng

    When building, I get this error.

    java.io.IOException: Cannot run program "/home/xander/Code/W-OVERFLOW/Debugify/forge/build/machete-build/oxipng": error=2, No such file or directory
    	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
    	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
    	at io.github.p03w.machete.util.InvokeProcessKt.invokeProcess(invokeProcess.kt:11)
    	at io.github.p03w.machete.core.OxipngManager.optimize(OxipngManager.kt:106)
    	at io.github.p03w.machete.core.JarOptimizer.optimizePNG(JarOptimizer.kt:57)
    	at io.github.p03w.machete.core.JarOptimizer.optimize(JarOptimizer.kt:141)
    	at io.github.p03w.machete.tasks.OptimizeJarsTask.optimizeJars(OptimizeJarsTask.kt:29)
    	at java.base/java.util.Optional.orElseGet(Optional.java:364)
    

    I believe this is because I have a multiproject build and oxipng is only being downloaded for the root project.

    Maybe consider this:

    1. Use system-provided oxipng if present
    2. Always run oxipng from rootProject
    opened by isXander 17
  • Doesn't work on Bodacious Berries

    Doesn't work on Bodacious Berries

    In my mod Bodacious Berries I have this disaster of a blockstate which seems to explode when compiled with Machete 1.0.6.
    I'm not sure what causes this, but when my mod is compiled with Machete grapevines have no textures or models, which I can pretty safely say is because of Machete encountering an error when dealing with that blockstate file. Please fix this so I can use Machete in my project and recommend it to friends :) it's a really nice tool!

    opened by ix0rai 3
  • Doesnt work on some linux (and/or mac) environments?

    Doesnt work on some linux (and/or mac) environments?

    Alright whee

    Please provide:

    • The version of the plugin you are using
    • Your distro
    • Anything weird you did to permissions
    • idk anything useful thanks

    I cant reproduce on my mint VM so idk what to do

    opened by SilverAndro 1
  • Dont compress files under a certain size

    Dont compress files under a certain size

    The compression dictionary can actually expand the size of certain files

    "Dont compress under X" is a quick fix, maybe add an option to properly test each file?

    opened by SilverAndro 1
Owner
Silver
Minecraft mod developer, mostly doing server-side and modpack utility dev in Kotlin.
Silver
gradle-android-scala-plugin adds scala language support to official gradle android plugin

gradle-android-scala-plugin gradle-android-scala-plugin adds scala language support to official gradle android plugin. See also sample projects at htt

saturday06 345 Dec 10, 2022
Ownership-gradle-plugin - Gradle code ownership verification plugin

Gradle code ownership verification plugin A gradle plugin that will verify owner

null 4 Dec 15, 2022
Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Central, Corporate staging/snapshot servers and local Maven repositories).

GradleMavenPush Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Cen

 Vorlonsoft LLC 21 Oct 3, 2022
A flutter plugin through which you can get audios, videos, or images from the local storage.

Getter Made flutter easier. Description A flutter plugin through which you can get audios, videos or images from the local storage. Dependencies Befor

Younes Lagmah 3 Sep 11, 2021
A small plugin which loads an additional properties file for secret values.

Gradle Secrets Plugin A small plugin which loads an additional properties file for secret values. Why Using this plugin, you can have an additional fi

null 7 Dec 25, 2022
A Intellij platform plugin to view truetype font file(.ttf) that includes icon glyphs usually

Icon Font Viewer 一个用于查看.ttf字体文件的Intellij平台(支持IDEA/Android Studio等)的插件,通常用于展示icon

null 7 Oct 22, 2022
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.

Gradle Play Publisher Gradle Play Publisher is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and

null 3.9k Dec 30, 2022
Gradle plugin which downloads and manages your Android SDK.

DEPRECATED This plugin is deprecated and is no longer being developed. Tools and dependencies are automatically downloaded using version 2.2.0 of the

Jake Wharton 1.4k Dec 29, 2022
CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native.

C Klib CKlib is a gradle plugin that will build and package C/C++/Objective-C code for Kotlin/Native. The Problem When you want to access C-etc code f

Touchlab 73 Nov 8, 2022