Spring-boot:Proguard混淆战争:WAR文件中没有主清单属性

时间:2018-06-25 17:12:35

标签: maven spring-boot proguard war meta-inf

我们正在尝试对Spring Boot Application进行混淆。 对于混淆,我们使用 proguard

我所做的配置是

<build>
    <plugins>

        <plugin>
            <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>
                <!-- File with proguard configuration -->
                <proguardInclude>${basedir}/build/proguard.conf</proguardInclude>
                <obfuscate>true</obfuscate>
                <includeDependency>true</includeDependency>
                <injar>${project.build.finalName}.${project.packaging}</injar>
                <outjar>${project.build.finalName}-proguard.${project.packaging}</outjar>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>${version.net.sf.proguard}</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>com.Application</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>

                    </goals>

                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

当我尝试构建应用程序时,它是在实际war文件中创建METAINF.MF文件,而不是在混淆后的war文件中创建

我还提供了 maven-assembly-plugin 插件,然后再提供模糊处理和spring组装软件包。

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>assembly</id>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.Application</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <appendAssemblyId>false</appendAssemblyId>
                <attach>false</attach>
            </configuration>
        </plugin>

任何人都可以建议我需要提供的其他配置。

我尝试过重新排列插件的排列,但没有成功。

是否可以在Spring Boot Maven插件中定义档案清单属性?

1 个答案:

答案 0 :(得分:0)

我们现在已经改变了方法。

仅通过混淆软件包将无法解决此问题。在这之后,您可能会 步骤:

  1. 首先,我们使用maven-war-plugin创建战争
  2. 打开战争包装,将需要混淆的文件保存在一个文件夹中,将jar保存在另一个文件夹中
  3. 使用maven ant插件再次打包。
<build>
        <finalName>Application</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.Application</mainClass>
                        </manifest>
                    </archive>
                    <appendAssemblyId>false</appendAssemblyId>
                    <attach>false</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.14</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <proguardVersion>5.2.1</proguardVersion>
                    <injar>Application/WEB-INF/lib</injar>
                    <outjar>Application/WEB-INF-OB/lib</outjar>
                    <proguardInclude>${basedir}/proguard.conf</proguardInclude>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>antbuild</id>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <property name="build.compiler" value="extJavac" />
                                <ant dir="${basedir}" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant</artifactId>
                        <version>${ant.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.ivy</groupId>
                        <artifactId>ivy</artifactId>
                        <version>2.4.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-antlib</artifactId>
                        <version>2.0.2.RELEASE</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

蚂蚁脚本:

<project xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:spring-boot="antlib:org.springframework.boot.ant" name="spring-boot-sample-ant" default="build">

    <description>
        Sample ANT build script for a Spring Boot executable JAR project. Uses ivy for
        dependency management and spring-boot-antlib for additional tasks. Run with
        '$ ant -lib ivy-2.2.jar spring-boot-antlib.jar' (substitute the location of your
        actual jars). Run with '$ java -jar target/*.jar'.
    </description>

    <property name="ant-spring-boot.version" value="${revision}" />
    <property name="lib.dir" location="${basedir}/target/lib" />
    <property name="start-class" value="com.Application" />

    <target name="resolve" description="--> retrieve dependencies with ivy">
        <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />
    </target>

    <target name="classpaths" depends="resolve">
        <path id="compile.classpath">
            <fileset dir="${lib.dir}/compile" includes="*.jar" />
        </path>
    </target>

    <target name="init" depends="classpaths">
        <mkdir dir="target/classes" />
    </target>

    <target name="compile" depends="init" description="compile">
        <javac srcdir="src/main/java" destdir="Application/WEB-INF/classes" classpathref="compile.classpath" />
    </target>

    <target name="clean" description="cleans all created files/dirs">
        <delete dir="target" />
    </target>

    <target name="build">
        <spring-boot:exejar destfile="target/${ant.project.name}-${ant-spring-boot.version}.jar" classes="target/Application/WEB-INF/classes">
            <spring-boot:lib>
                <fileset dir="target/Application/WEB-INF-OB/lib" />
            </spring-boot:lib>
        </spring-boot:exejar>
    </target>
    <!-- Manual equivalent of the build target -->
    <target name="manual">
        <war destfile="target/${ant.project.name}-${ant-spring-boot.version}.war" compress="false">
            <mappedresources>
                <fileset dir="target/Application/WEB-INF/classes" />
                <globmapper from="*" to="WEB-INF/classes/*" />
            </mappedresources>
            <mappedresources>
                <fileset dir="src/main/resources" erroronmissingdir="false" />
                <globmapper from="*" to="WEB-INF/classes/*" />
            </mappedresources>
            <mappedresources>
                <fileset dir="target/Application/WEB-INF/lib" />
                <globmapper from="*" to="WEB-INF/lib/*" />
            </mappedresources>
            <zipfileset src="target/Application/WEB-INF/lib/spring-boot-loader-tools-1.5.9.RELEASE.jar" />
            <manifest>
                <attribute name="Main-Class" value="org.springframework.boot.loader.JarLauncher" />
                <attribute name="Start-Class" value="${start-class}" />
            </manifest>
        </war>
    </target>
</project>

这应该可以解决问题。