首页 文章

阴影,proguard和appassembler maven插件的组合

提问于
浏览
0

我正在尝试使用maven构建和混淆多模块项目 . 我使用shade插件创建一个包含我自己的所有类文件(每个模块)的胖jar,这样我就可以使用proguard-maven-plugin对fat jar进行模糊处理,然后使用appassembler插件创建可执行的构建输出 . 除了其他模块依赖项也出现在appassembler repo dir中之外,一切正常,这是错误的,因为模糊的jar中已经存在模糊的类 .

我已经尝试定义提供的其他模块依赖项,然后为shade插件添加依赖项,但是shade插件似乎忽略了它们 .

这是pom.xml的相关部分:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <outputFile>${project.build.directory}/${project.build.finalName}-shaded.${project.packaging}</outputFile>
                        <artifactSet>
                            <includes>
                                <include>${project.groupId}:*</include>
                            </includes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>module-a</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>module-b</artifactId>
                    <version>${project.version}</version>
                </dependency>
            </dependencies>
        </plugin>

        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.13</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <injar>${project.build.finalName}-shaded.${project.packaging}</injar>
                <outjar>${project.build.finalName}.${project.packaging}</outjar>
                <proguardInclude>proguard.pro</proguardInclude>
                <maxMemory>1024m</maxMemory>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                    <lib>${java.home}/lib/jce.jar</lib>
                </libs>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>2.0.0</version>
            <executions>
                <execution>
                    <id>assemble</id>
                    <phase>package</phase>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                    <configuration>
                        <programs>
                            <program>
                                <mainClass>my.package.Application</mainClass>
                            </program>
                        </programs>
                        <useWildcardClassPath>true</useWildcardClassPath>
                        <repositoryLayout>flat</repositoryLayout>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

欢迎任何想法 .

2 回答

  • 0

    我找到了一个不像我想的那样方便的解决方案,但它比手动移除其他模块 jar 更好 . 我使用程序集插件从构建分发zip中排除jar .

    pom.xml中:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <outputFile>${project.build.directory}/${project.build.finalName}-shaded.${project.packaging}</outputFile>
                            <artifactSet>
                                <includes>
                                    <include>${project.groupId}:*</include>
                                </includes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.13</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <injar>${project.build.finalName}-shaded.${project.packaging}</injar>
                    <outjar>${project.build.finalName}.${project.packaging}</outjar>
                    <proguardInclude>proguard.pro</proguardInclude>
                    <maxMemory>1024m</maxMemory>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jce.jar</lib>
                    </libs>
                </configuration>
            </plugin>
    
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>2.0.0</version>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                        <configuration>
                            <programs>
                                <program>
                                    <mainClass>my.package.Application</mainClass>
                                </program>
                            </programs>
                            <useWildcardClassPath>true</useWildcardClassPath>
                            <repositoryLayout>flat</repositoryLayout>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>descriptor.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    descriptor.xml:

    <assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
          xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
    <id>distribution</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/appassembler</directory>
            <excludes>
                <exclude>**/module-a-${project.version}.${project.packaging}</exclude>
                <exclude>**/module-b-${project.version}.${project.packaging}</exclude>
            </excludes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
    
  • 1

    我认为你的问题来自于阴影jar和appassembler在同一阶段,包中运行的事实 .

    我认为你应该尝试将appassembler插件的阶段修改为:

    <phase>post-package</phase>
    

相关问题