混淆依赖于 war 的项目

Obfuscating a project dependent on a war

我想使用 ProGuard(项目 A)混淆项目 (jar)。然而,这个项目依赖于另一个war(项目B)并使用了我在B中开发的一些类。 我使用了这个问题的解决方案:Build a jar from a maven project dependent on other project 但它没有用,当我使用命令时 maven clean install -X 在项目 A 上我得到错误:

error: cannot find symbol

error: package com.example does not exist

如何混淆这个 jar?

编辑 1

在项目 A 的 POM 中我有:

  1. 我的war依赖关系:

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>myWarProject</artifactId>
        <version>1.0.0-BUILD-SNAPSHOT</version>
    </dependency>
    
  2. 在构建部分:

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <finalName>DeviceListener</finalName>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>com.example.main.Main</Main-Class>
                                    <Build-Number>1</Build-Number>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

在项目 B 中我有:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <attachClasses>true</attachClasses>
            </configuration>
        </plugin>

我的意思是为 war 项目中的 类 创建一个 jar,如下所示:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <attachClasses>true</attachClasses>
                <archiveClasses>true</archiveClasses>
            </configuration>
        </plugin>
    </plugins>
</build>

这会生成一个补充 jar 文件,其中包含 war 项目的 类,可以用作依赖项(不要忘记定义分类器)..

您需要像这样更改您的依赖项:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>myWarProject</artifactId>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <classifier>classes</classifier>
</dependency>