0

我正在尝试使用 maven 构建和混淆一个多模块项目。我使用 shade 插件创建一个包含我自己的所有类文件(每个模块)的 fat jar,以便我可以使用 proguard-maven-plugin 混淆 fat jar,然后使用 appassembler 插件创建可执行的构建输出。一切正常,除了其他模块依赖项也出现在 appassembler repo 目录中,这是错误的,因为混淆的类已经存在于阴影 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>
            <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>

欢迎任何想法。

4

2 回答 2

1

我找到了一个不像我想要的那么方便的解决方案,但它比手动删除其他模块 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>

描述符.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>

于 2017-03-01T09:10:46.350 回答
0

我认为您的问题来自这样一个事实,即阴影 jar 和 appassembler 在同一阶段运行,package

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

<phase>post-package</phase>
于 2017-02-28T14:03:48.073 回答