Java – How can I use the Gradle Proguard plugin as a Maven repository dependency? (Local folders are not referenced.) )

How can I use the Gradle Proguard plugin as a Maven repository dependency? (Local folders are not referenced.) )… here is a solution to the problem.

How can I use the Gradle Proguard plugin as a Maven repository dependency? (Local folders are not referenced.) )

To use Proguard’s gradle plugin, use Proguard Gradle manual The methods provided in must manually download Proguard and place it in a local folder. Especially the manual says:

One way is to add the following line to your build.gradle file

The manual provides the following build.gradle

buildscript {
    repositories {
        flatDir dirs: '/usr/local/java/proguard/lib'
    }
    dependencies {
        classpath ':proguard:'
    }
}

It’s worth noting that this is just “one way” to add a confused.
The path can be made more parametric by defining it as a variable to easily migrate from one obfuscator build to another, but it’s not that portable.

What is needed is to use the obfuscator

without configuring the programmer’s workspace, it is better to download the obfuscator from the Maven repository.
This saves time and reduces errors in situations such as building projects in CI such as Jenkins or using projects in different environments.

Solution

I came up with the following gradle script:

    // Tell Gradle where to find the ProGuard task.
    buildscript {
        repositories {
            mavenLocal() //in case it is already downloaded
            mavenCentral()
        }//end repositories

dependencies { classpath 'net.sf.proguard:proguard-gradle:6.0.3' }
    }//end buildscript

This method works fine and it seems fine to use the obfuscator in the repository. See also in sourceforge .

Rationale: The “/usr/local/java/proguard/lib” folder contains only Proguard’s jar, and using proguard-gradle as a dependency will also get the other dependencies you need.

Related Problems and Solutions