Skip to content

Commit

Permalink
Issue wvengen#161: Include transitive dependencies in Proguard classpath
Browse files Browse the repository at this point in the history
Otherwise Kotlin obfuscation or obfuscation with newer version fails.
  • Loading branch information
lasselindqvist committed Sep 27, 2021
1 parent d4e1f72 commit e6fca6c
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,27 @@ private void attachTextFile(File theFile, String mainClassifier, String suffix)

}
}

private Set<File> getAllPluginArtifactDependencies(ProGuardMojo mojo) throws MojoExecutionException {
Set<File> files = new HashSet<>(getProguardJars(mojo));
for (Artifact artifact : mojo.pluginArtifacts) {
files.add(artifact.getFile().getAbsoluteFile());
files.addAll(getChildArtifacts(artifact));
}

return files;
}

private Set<File> getChildArtifacts(Artifact artifact) {
Set<File> files = new HashSet<>();
for (Object child : artifact.getDependencyTrail()) {
if (child instanceof Artifact) {
files.add(((Artifact) child).getFile().getAbsoluteFile());
files.addAll(getChildArtifacts((Artifact) child));
}
}
return files;
}

private List<File> getProguardJars(ProGuardMojo mojo) throws MojoExecutionException {

Expand Down Expand Up @@ -984,8 +1005,10 @@ private void proguardMain(Collection<File> proguardJars, List<String> argsList,
java.setTaskName("proguard");

mojo.getLog().info("proguard jar: " + proguardJars);

Set<File> allDependencyFiles = getAllPluginArtifactDependencies(mojo);

for (File p : proguardJars)
for (File p : allDependencyFiles)
java.createClasspath().createPathElement().setLocation(p);
// java.createClasspath().setPath(System.getProperty("java.class.path"));
java.setClassname(mojo.proguardMainClass);
Expand Down

0 comments on commit e6fca6c

Please sign in to comment.