I want to add ProGuard obfuscation to my Java project, to automatically obfuscate the JAR when building it. I created a default build.gradle
file, added my dependencies and pasted in what ProGuard has on their website. I keep getting an error.
The error:
Could not get unknown property 'ProGuardTask' for root project 'MCPets-multipet-gradle' of type org.gradle.api.Project.
build.gradle file:
// ProGuard
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.7.0'
}
}
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven{url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'}
maven{url = 'https://repo.papermc.io/repository/maven-public/'}
maven{url = 'https://libraries.minecraft.net/'}
maven{url = 'https://mvn.lumine.io/repository/maven-public/'}
maven{url = 'https://maven.enginehub.org/repo/'}
maven{url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'}
maven{url = 'https://oss.sonatype.org/content/repositories/snapshots'}
maven{url = 'https://jitpack.io'}
}
dependencies {
// Technical dependencies
compileOnly("org.projectlombok:lombok:1.18.38")
annotationProcessor("org.projectlombok:lombok:1.18.38")
implementation 'com.google.code.gson:gson:2.8.9'
// Minecraft dependencies
implementation 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT'
implementation 'io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT'
// Plugin dependencies
implementation 'io.lumine:Mythic-Dist:5.6.0-SNAPSHOT'
implementation 'com.sk89q.worldguard:worldguard-bukkit:7.0.7-SNAPSHOT'
implementation 'me.clip:placeholderapi:2.11.6'
implementation 'net.luckperms:api:5.4'
implementation 'com.ticxo.modelengine:ModelEngine:R4.0.6'
implementation 'com.github.LoneDev6:api-itemsadder:3.6.1'
}
// ProGuard
tasks.register('proguard', ProGuardTask) {
configuration file('proguard.pro')
injars(tasks.named('jar', Jar).flatMap { it.archiveFile })
// Automatically handle the Java version of this build.
if (System.getProperty('java.version').startsWith('1.')) {
// Before Java 9, the runtime classes were packaged in a single jar file.
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
}
else {
// As of Java 9, the runtime classes are packaged in modular jmod files.
libraryjars "${System.getProperty('java.home')}/jmods/java.base.jmod", jarfilter: '!**.jar', filter: '!module-info.class'
//libraryjars "${System.getProperty('java.home')}/jmods/....."
}
verbose
outjars(layout.buildDirectory.file("libs/${baseCoordinates}-minified.jar"))
}
Solved!
All I needed to do is add import proguard.gradle.ProGuardTask
at the top..