yGuard task fails to retain module-info.class files
doriancransac opened this issue · comments
Hi,
The documentation says that yGuard supports java modules (although does not rename them, which is fine), however my obfuscated jars seem to "lose" the module-info.class files:
Here's my task (I believe all I did in comparison to the original examples is just remove the keep element) :
task obfuscate {
dependsOn jar
group 'yGuard'
description 'Obfuscates and shrinks the java archive.'
doLast {
ant.taskdef(
name: 'yguard',
classname: 'com.yworks.yguard.YGuardTask',
classpath: sourceSets.main.runtimeClasspath.asPath
)
def archivePath = jar.archiveFile.get().asFile.path
ant.yguard {
inoutpair(in: archivePath, out: archivePath.replace(".jar", "_obf.jar"))
// don't let the obfuscator remove the "Deprecated" attributes from the .class file entries
attribute(name: "Deprecated")
shrink(logfile: "${buildDir}/yshrink.log.xml") {
}
rename(logfile: "${buildDir}/yguard.log.xml") {
}
}
}
and the dependency I'm using:
compile "com.yworks:yguard:2.9.1"
What am I doing wrong? Also could you maybe briefly explain how leaving module names untouched is going to work at runtime if the corresponding packages have been renamed...? I searched the docs but couldn't find any details about this.
Thanks in advance.
EDIT: I figured in the meantime that I may need to add an explicit keep instruction, but can't (yet) find one that effectively retains the module-info.class file, this is what I've tried so far:
rename(logfile: "${buildDir}/yguard.log.xml") {
//keep {'class'(name: 'module-info')}
//keep(sourcefile: 'module-info.java')
//keep(sourcefile: 'module-info')
keep(sourcefile: 'module-info.class')
}
Hey @doriancransac you should try this:
shrink(...) {
keep {
'class'(name: "module-info")
}
}
Module-info files are essentially Java classes being named module-info
. I gave it a quick try with the Java 9 modules sample, this seems to work.
Please let me know if it can be closed or if the issue persist.
Closing because of inactivity.