Can't build project when building for Java instead of Kotlin with Gradle
I included this code at the top of the file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.6.1'
}
}
I included this code after the plugins and dependencies:
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"))
}
And when reloading the build.gradle I get this error:
Build file 'D:\MasterThesis\testSubjects\proguard\spring-petclinic-main\build.gradle' line: 72
A problem occurred evaluating root project 'spring-petclinic'.
> Could not get unknown property 'ProGuardTask' for root project 'spring-petclinic' of type org.gradle.api.Project.
Also there doesn't seem to be any instructions on how to use it for pure Java projects. Is it not possible to use Proguard for non-android applications?
Hello,
the instructions for pure java projects can be found at this link: https://www.guardsquare.com/manual/setup/gradle
The setup looks fine, are you correctly importing ProGuardTask at the top of your gradle file?
import proguard.gradle.ProGuardTask
Can you also try by using the fully qualified name?
tasks.register('proguard', proguard.gradle.ProGuardTask) {
...
}
you should use “task myProguardTask(type: proguard.gradle.ProGuardTask)” not “tasks.register('proguard', proguard.gradle.ProGuardTask)”,it works for me with gradle 8.10