aspectj-maven-plugin

AspectJ maven plugin compile time memory exceeds error


Hi I am using compile time AspectJ to weave classes However some classes are so big that at compile time it is not able to weave it.

so I have already tried adding argument in plugin: -Xmx2048m

pom.xml:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11</version>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjrt</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjtools</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <argLine>-Xmx2048m</argLine>
                    <complianceLevel>${maven.compiler.target}</complianceLevel>
                    <source>${maven.compiler.target}</source>
                    <target>${maven.compiler.target}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <Xlint>ignore</Xlint>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <forceAjcCompile>true</forceAjcCompile>
                    <sources />
                    <weaveDirectories>
                        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
                    </weaveDirectories>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

error log:

Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.11:compile (default) on project lsmvAdverseEvent: AJC compiler errors:
[ERROR] error at SafetyMBean.java::0 The class com.x.y.z.MBean exceeds the maximum class size supported by the JVM (constant pool too big).
[ERROR] abort ABORT -- (RuntimeException) key not found in wovenClassFile
[ERROR] key not found in wovenClassFile
[ERROR] java.lang.RuntimeException: key not found in wovenClassFile
[ERROR] java.lang.RuntimeException: key not found in wovenClassFile
[ERROR]     at org.aspectj.weaver.WeaverStateInfo.findEndOfKey(WeaverStateInfo.java:408)
[ERROR]     at org.aspectj.weaver.WeaverStateInfo.replaceKeyWithDiff(WeaverStateInfo.java:364)
[ERROR]     at org.aspectj.weaver.bcel.LazyClassGen.getJavaClassBytesIncludingReweavable(LazyClassGen.java:711)

How to solve this issue Please Help?


Solution

  • Here is how I resolved this issue. I faced this issue when I run the mvn clean install command.

    enter image description here

    1. Open your Java project with IntelliJ IDEA.
    2. Go to "File" > "Settings" (or "IntelliJ IDEA" > "Preferences" on macOS).
    3. Navigate to "Build, Execution, Deployment" > "Build Tools" > "Maven".
    4. Look for the "Runner" section.
    5. In the "VM options" field, add -Xmx2048m to set the maximum heap size to 2048 MB. If there are existing arguments make sure to separate it from any existing options with a space.
    6. Click "OK" to apply the changes and close the settings window.
    7. Close any unnecessary software running in the background to free up memory that is currently being utilized.
    8. Now, please try to run mvn clean install command.

    Now, whenever you run Maven commands within IntelliJ IDEA, it will use the options you've set, including the maximum heap size of 2048 MB (-Xmx2048m). This can help prevent memory-related issues, especially when working on larger projects.

    References: java.lang.OutOfMemoryError: Java heap space Error