Proguard ant task fails after update to v7.2.1

Hi,

I’ve been using proguard for several years to obfuscate my Java application via an ant build file.

I recently had to update to proguard 7.2.1 (from v6.2.2) after moving from Java 8 to Java 17.

I now get this error when running my build:

BUILD FAILED
~\myproject\build.xml:102: java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager
        at proguard.ProGuard.<clinit>(ProGuard.java:59)
        at proguard.ant.ProGuardTask.execute(ProGuardTask.java:332)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
        at jdk.internal.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
        at org.apache.tools.ant.Task.perform(Task.java:350)
        at org.apache.tools.ant.Target.execute(Target.java:449)
        at org.apache.tools.ant.Target.performTasks(Target.java:470)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
        at org.apache.tools.ant.Main.runBuild(Main.java:818)
        at org.apache.tools.ant.Main.startAnt(Main.java:223)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.LogManager
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1402)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1357)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1112)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 18 more

I’ve tried to strip down my build.xml to the bare minimum, which basically amounts to:

<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard-ant-7.2.1.jar:lib/proguard-base-7.2.1.jar:lib/proguard-core-8.0.7.jar" />

<!-- build and locate jar -->

<proguard>
  -injars ${original.jar}
  -outjars ${obfuscated.jar}
</proguard>

but I still get the same error.

I’ve also tried adding Log4j to the classpath and to the library jars, but that didn’t fix the problem either.

Hi @ptreitler,

Welcome to the PG Community!

We started using Log4J in 7.2 and these classes are missing from your classpath.

This is because you added these individual jars to the classpath:
<taskdef resource="proguard/ant/task.properties" classpath="lib/proguard-ant-7.2.1.jar:lib/proguard-base-7.2.1.jar:lib/proguard-core-8.0.7.jar" />

instead of the fat jar (which is the correct option for you!)
lib/proguard-ant.jar

which is distributed in the release zip. And is what you really need here.

The fat jar contains the Log4J dependency which should resolve the error you’re seeing, based on my testing. :slight_smile:

The manual also shows using the fat jar:

Please let me know if this approach works, or if anything is not clear.

Kind regards,

Jack

Thanks @jack, it works and the proguard task is running again!

1 Like