配置proguard-maven-plugin过滤库jar的META-INF

J. *_*ohn 5 java log4j proguard maven

我正在尝试使用ProGuard混淆我的Java 8 jar。我无法在pom.xml文件中配置ProGuard插件,以便将所需的配置发送给ProGuard。

背景:

我的依赖项之一取决于Log4j 2.9.1。我在ProGuard中遇到了一个有据可查的错误-https: //sourceforge.net/p/proguard/bugs/665/

作为解决方法,建议将过滤器添加到log4j库以忽略META-INF类。

-libraryjars "log4j-api-2.9.0.jar"(!META-INF/versions/9/**.class)
Run Code Online (Sandbox Code Playgroud)

问题:

我无法成功配置Maven插件以将此配置发送给ProGuard。

(注意:maven插件会自动为log4j添加-libraryjars配置,因为它是项目依赖项。)

失败的尝试#1:

我尝试添加一个排除项以防止该库被自动包含,并尝试添加一个lib条目以将其与过滤器一起添加。

<exclusions>
  <exclude>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
  </exclude>
</exclusions>
<libs>
  <lib>${env.LOG4J_REPOSITORY}/log4j-api-2.9.1.jar(!META-INF/versions/**.class)</lib>
</libs>
Run Code Online (Sandbox Code Playgroud)

排除成功,但lib条目失败。它被视为文件名,因此ProGuard的参数看起来像

-libraryjars, '/mnt/juser/repository/org/apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar(!META-INF/versions/**.class)',
Run Code Online (Sandbox Code Playgroud)

我得到了错误

 [proguard] Error: Can't read [/mnt/juser/repository/org/apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar(!META-INF/versions/**.class)] (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

我试图在lib声明中添加标点符号

<lib>"${env.LOG4J_REPOSITORY}/log4j-api-2.9.1.jar"(!META-INF/versions/**.class)</lib>
Run Code Online (Sandbox Code Playgroud)

它为ProGuard创建了这个参数

-libraryjars, '"/mnt/juser/repository/org/apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar"(!META-INF/versions/**.class)',
Run Code Online (Sandbox Code Playgroud)

并因以下错误而失败

[proguard] Error: Can't read [/home/juser/working/"/mnt/juser/repository/org/apache/logging/log4j/log4j-api/2.9.1/log4j-api-2.9.1.jar"(!META-INF/versions/**.class)] (No such file or directory)
Run Code Online (Sandbox Code Playgroud)

失败尝试#2

我尝试使用包含项来显式添加带有过滤器的此库。

<assembly>
  <inclusions>
    <inclusion>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <library>true</library>
      <filter>!META-INF/versions/**.class</filter>
    </inclusion>
  </inclusions>
</assembly>
Run Code Online (Sandbox Code Playgroud)

该库被列为-libraryjars条目,但没有过滤器。

mmd*_*bas 0

我遇到了同样的问题。以下配置对我有用:

<plugin>
    <groupId>com.github.wvengen</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <configuration>
        <exclusions>
            <!-- exclude the artifact -->
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-api</artifactId>
            </exclusion>
        </exclusions>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals><goal>proguard</goal></goals>
        </execution>
        <execution>
            <id>obfuscate-uber</id>
            <phase>package</phase>
            <goals><goal>proguard</goal></goals>
            <configuration>
                <injar>${project.build.finalName}-uber.jar</injar>
                <outjar>${project.build.finalName}-uber.jar</outjar>
                <!-- filter out unwanted parts -->
                <inFilter>!META-INF/versions/9/**.class</inFilter>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)