yWorks / yGuard

The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts

Home Page:https://yworks.github.io/yGuard/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with uber-jar obfuscation (Self-contained executable jar)

ASharifullin opened this issue · comments

I'm trying to obfuscate an uber-jar and I'm encountering an error (It complains about different classes, this is an example):

[ant:rename] yGuard detected a duplicate class definition for
ch.qos.logback.classic.spi.TurboFilterList
[jar:C:\Home\Projects\am\build\distributions\uberJar\am.jar|ch/qos/logback/classic/spi/TurboFilterList.class] in
[jar:C:\Home\Projects\am\build\distributions\uberJar\am.jar|LIB-INF/shared/ch/qos/logback/classic/spi/TurboFilterList.class]
Please remove inappropriate duplicates first!

It complains about project dependencies that are included in the uber-jar. Adding dependency packages to the 'keep' block does not help:

task obfuscate {
dependsOn buildUberJar
group 'yGuard'
description 'Obfuscates and shrinks the java archive.'

doLast {
  ant.taskdef(
          name: 'yguard',
          classname: 'com.yworks.yguard.YGuardTask',
          classpath: configurations.yguard.asPath
  )

  def archivePath = "build/distributions/uberJar/am.jar"

  ant.yguard {
      inoutpair(
              in: archivePath,
              out: layout.buildDirectory.file("tmp/am-plain-obf.jar").get().asFile.path
      )

      rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") {
          keep {
              'class'(
                      classes: 'protected'
              )

              'package' {
                  patternset {
                      include(name: 'com.haulmont.**')
                      include(name: 'ch.qos.**')
                      include(name: 'org.apache.**')
                      include(name: 'javax.**')
                  }
              }
          }
      }
  }
}
}

yGuard has not been tested with and may not support "uber"-jars, properly. You will need to obfuscate the various jars, separately and rebundle them in the end.

That said, obfuscating third party jars is typically not a good idea, either. You don't know how the files have been compiled and whether the code uses techniques that doens't work after obfuscation. (If a regular jar really has duplicate class files, this indicates a real problem, e.g.). You should only obfuscate classes that you have compiled and jarred, regularly, ideally and reference third party jars as external classpath members.

If you think the jar is a regular jar file that adheres to the spec and uses the default class loading mechanisms, but still yGuard cannot deal with it, then please provide a reduced test-case for a specific issue. Thanks!