2

我想用 ProGuard 混淆我的库,并将以下代码添加到pom.xml

<build>
    <plugins>
        ...
        <plugin>
            <groupId>com.pyx4me</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <options>
                    <option>-allowaccessmodification</option>
                    <option>-keep class mypackage.AbstractSimulationFacadeTest</option>
                </options>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                </libs>
            </configuration>
        </plugin>
    </plugins>
</build>

mypackage.AbstractSimulationFacadeTest是在 中定义的类src/test/java。它用于单元测试。

当我运行时mvn install,ProGuard 抱怨它找不到类mypackage.AbstractSimulationFacadeTest

[proguard] Note: the configuration refers to the unknown class 'mypackage.AbstractSimulationFacadeTest'
[proguard] Note: there were 1 references to unknown classes.
[proguard]       You should check your configuration for typos.
[proguard] Error: The output jar is empty. Did you specify the proper '-keep' options?

当我删除线

<option>-keep class mypackage.AbstractSimulationFacadeTest</option>

并运行mvn install,我得到一个ClassNotFoundErrorfor mypackage.AbstractSimulationFacadeTest

我应该如何更改我的pom.xml文件以使mvn install运行没有错误?

4

1 回答 1

2

尝试迁移到新版本的 pro guard 插件。您使用的是默认版本,即 2.0.4。快速搜索一下 maven ,发现 GitHub 上有一个更新的版本,但是在不同的 group id 下:

<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.6</version>

这应该让您使用 ProGuard 4.8,它可能会解决这个问题。

此外,查看Pro Guard 文档,您的 -keep 选项应该是您正在构建的工件(src/main/java 中的代码)的入口点,而不是测试用例的入口点。

最后,在我看来,您已经将抽象测试用例从 src/main/java 移至 src/test/java。如果是这种情况,您可能需要执行mvn clean install来清理目标目录。Pro Guard 可能会从项目的先前版本中找到旧类。

于 2012-11-19T20:15:49.787 回答