Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade for parameter transformer
Asked Answered
W

2

5

I am trying to get the log4j2 configured for my aws lambda function using java8 runtime. Aws lambda handler does provide context-Lambdalogger but I want to use the standard log4j configuration so that it can be declared in every class and log it as required without passing the context-Lambdalogger to every method and so on. As per aws documentation I have tried to use the below dependencies and plugin as mentioned below. But I get the below error . Any clues or idea can help.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade (default) on project lcc: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade for parameter transformer: Cannot create instance of interface org.apache.maven.plugins.shade.resource.ResourceTransformer: org.apache.maven.plugins.shade.resource.ResourceTransformer.<init>() -> [Help 1]



< dependency><br/>
      < groupId>com.amazonaws< /groupId><br/>
      < artifactId>aws-lambda-java-log4j2< /artifactId><br/>
      < version>1.0.0< /version><br/>
    < /dependency><br/>
    < dependency><br/>
      < groupId>org.apache.logging.log4j< /groupId><br/>
      < artifactId>log4j-core< /artifactId>
      < version>2.8.2< /version><br/>
    < /dependency><br/>
    < dependency><br/>
      < groupId>org.apache.logging.log4j< /groupId><br/>
      < artifactId>log4j-api< /artifactId><br/>
      < version>2.8.2< /version><br/>
< /dependency><br/>


< plugin><br/>
        < group Id>org.apache.maven.plugins< /group Id><br/>
        < artifactId>maven-shade-plugin< /artifactId><br/>
        < version>3.0.0< /version><br/>
        < executions><br/>
          < execution><br/>
            < phase>package< /phase><br/>
            < goals><br/>
              < goal>shade< /goal><br/>
            < /goals><br/>
            < configuration><br/>
              < transformers><br/>
                < transformer><br/>
                        implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer"><br/>
                < /transformer><br/>
              < /transformers><br/>
            < /configuration><br/>
          < /execution><br/>
        < /executions><br/>
        < dependencies><br/>
          < dependency><br/>
            < group Id>com.github.edwgiz< /group Id><br/>
            < artifact Id>maven-shade-plugin.log4j2-cachefile-transformer< /artifactId><br/>
            < version>2.8.1< /version><br/>
          < /dependency><br/>
        < /dependencies><br/>
< /plugin>
Warmup answered 18/4, 2019 at 14:59 Comment(0)
W
3

I finally figured it out! There seems to be some compatibility issues with the plugin version 3.0.0 when using the transformer. I downgraded the plugin to version 2.3 and now it works fine.

The shade plugin is now able to create the uber jar with all the log components pulled into it.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <createDependencyReducedPom>false</createDependencyReducedPom>
        <transformers>
            <transformer
                    implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
            </transformer>
        </transformers>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.github.edwgiz</groupId>
            <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
            <version>2.8.1</version>
        </dependency>
    </dependencies>
</plugin>
Warmup answered 23/4, 2019 at 13:26 Comment(1)
is it working when the path of <transformer..../> is not under <executions></executions>Seko
V
10

This issue is resolved when using the latest version of the Plugin

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Vitrify answered 28/6, 2021 at 0:27 Comment(0)
W
3

I finally figured it out! There seems to be some compatibility issues with the plugin version 3.0.0 when using the transformer. I downgraded the plugin to version 2.3 and now it works fine.

The shade plugin is now able to create the uber jar with all the log components pulled into it.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <createDependencyReducedPom>false</createDependencyReducedPom>
        <transformers>
            <transformer
                    implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
            </transformer>
        </transformers>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.github.edwgiz</groupId>
            <artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
            <version>2.8.1</version>
        </dependency>
    </dependencies>
</plugin>
Warmup answered 23/4, 2019 at 13:26 Comment(1)
is it working when the path of <transformer..../> is not under <executions></executions>Seko

© 2022 - 2024 — McMap. All rights reserved.