简体   繁体   English

Proguard与Maven

[英]Proguard with Maven

I am trying to use Proguard to shrink the jar size. 我正在尝试使用Proguard来缩小罐子的大小。

I configured Proguard in Maven pom.xml. 我在Maven pom.xml中配置了Proguard。 It failed to find all the embedded dependency jars. 它找不到所有嵌入式的依赖罐。 It can read and parse out all dependency jars which is referenced in the current module, but for dependencies which are embedded in the other modules, it failed to find it. 它可以读取并解析当前模块中引用的所有依赖项jar,但是对于嵌入在其他模块中的依赖项,它找不到它。

For example, My current module is moduleA and it depends another module moduleB. 例如,我当前的模块是moduleA,它依赖于另一个模块moduleB。 And module B has a dependency moduleC. 并且模块B具有依赖性模块C。 It can find all classes which are directly inside moduleB, but it failed to parse out all classes which are inside moduleC. 它可以找到直接在moduleB内的所有类,但是无法解析出在moduleC内的所有类。 My configuration for proguard is as following: 我对proguard的配置如下:

<plugin>
            <!--groupId>com.pyx4me</groupId-->
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>proguard</id>
                <phase>package</phase>
                <goals>
                  <goal>proguard</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <injar>MyInput-${project.version}.jar</injar>
              <outjar>MyInput-Processed-${project.version}.jar</outjar>
              <options>
                <option>-keep public class * { *; }</option>
                <option>-ignorewarnings</option>
              </options>
              <libs>
                <!--lib>${java.bootstrap.classes}</lib>
                <lib>${java.cryptographic.extension.classes}</lib>
                <lib>${java.secure.socket.extension.classes}</lib-->
              </libs>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>net.sf.proguard</groupId>
                <artifactId>proguard-base</artifactId>
                <version>4.10</version>
                <scope>runtime</scope>
              </dependency>
            </dependencies>
        </plugin>

I had similar problem, however it could find the references mentioned in the plugin's configuration dependencies section. 我有类似的问题,但是它可以找到插件的配置依赖项部分中提到的引用。

However, if I tried to use the proguard-base-4.10 the proguard-maven-plugin (with com.pyx4me groupId) still used the proguard-4.3.jar (you can see it in the maven output in the console); 但是,如果我尝试使用proguard-base-4.10,则proguard-maven-plugin(带有com.pyx4me groupId)仍会使用proguard-4.3.jar(您可以在控制台的maven输出中看到它)。 looks like the plugin is only working with a "proguard" artifact, not a "proguard-base". 看起来该插件仅适用于“ proguard”构件,而不适用于“ proguard-base”构件。

So I configured the dependencies section to look like: 所以我将依赖项部分配置为:

<dependency>
  <groupId>net.sf.proguard</groupId>
  <artifactId>proguard</artifactId>
  <version>4.10</version>
  <scope>runtime</scope>
</dependency>

but this one is not available in the central maven repo (the latest version is 4.4). 但是该文件在中央Maven存储库中不可用(最新版本为4.4)。

What I did was to download the proguard-4.10 manually from proguard download section and install the proguard.jar in the local maven repository under the version 4.10 - and now everything works fine. 我要做的是从proguard下载部分手动下载proguard-4.10,然后将proguard.jar安装在本地maven存储库中的版本4.10下-现在一切正常。

该插件的更新版本位于: https : //github.com/wvengen/proguard-maven-plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM