Using AWS Powertools Tracing library with Java 17

115 Views Asked by At

I would like to use Powertools Tracing library for my Lambda. However, I am having issues setting things up.

According to their documentation, the aspectj-maven-plugin (dev.aspectj) should be added as a plugin. However, this causes compilation issues (related to Lombok). The exact logs are shown below this point.

[INFO] --- aspectj:1.13.1:compile (default) @ <module-name> ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: OpenJDK javac, ECJ
    <unknown source file>:<no line information>
[ERROR] log cannot be resolved

Maven section for aspectj-maven-plugin

<plugin>
    <groupId>dev.aspectj</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.13.1</version>
    <configuration>
        <source>17</source>
        <target>17</target>
        <complianceLevel>17</complianceLevel>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>software.amazon.lambda</groupId>
                <artifactId>powertools-tracing</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I have already followed some advice, such as adding -Djps.track.ap.dependencies=false to the Compiler settings of IntelliJ, which did not make a difference (I assumed that it had something to do with the warning issued by Lombok).

I can't find the exact same issue, but please let me know if you see a flaw in the way I set things up.

1

There are 1 best solutions below

0
On

You need to add to the aspectj-maven-plugin configuration to enable in-place weaving feature. Otherwise the plugin will ignore changes introduced by Lombok and will use .java files as a source.



 
<configuration>
    <forceAjcCompile>true</forceAjcCompile> 
    <sources/>
    <weaveDirectories>
        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
    </weaveDirectories>
    ...
    <aspectLibraries>
        <aspectLibrary>
            <groupId>software.amazon.lambda</groupId>
            <artifactId>powertools-logging</artifactId>
        </aspectLibrary>
    </aspectLibraries>
</configuration>

Source: https://docs.powertools.aws.dev/lambda/java/FAQs/