Using FindSecBugs in Maven throws java.lang.OutOfMemoryError

677 Views Asked by At

I'm new to Maven.I'm using Mac OSX. I tried to build the project using maven and it happened properly. Then I used mvn spotbugs:spotbugs to use the spotbugs plugin! It took a while and threw Exception in thread "main"

java.lang.OutOfMemoryError: Java heap space.

The project I tried is 330 MB which is quite big and I can do nothing about it for now.I tried many solutions online:

1.export MAVEN_OPTS="-Xmx2048m" (I tried increasing upto 12000m still wasn't working)

2.Used this plugin

       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
            <fork>true</fork>
            <meminitial>1024m</meminitial>
            <maxmem>8096m</maxmem>
        </configuration>
       </plugin>

and still didn't work.

Can anybody guide me through it? I'm using maven spotbugs version 3.1.12.

Using java 11,Maven 3

2

There are 2 best solutions below

0
On

The SpotBugs Maven Plugin has "How do I avoid OutOfMemory errors?" in its FAQ which I assume you have seen (since you tried MAVEN_OPTS="-Xmx2048m")

But there is one more thing there

You can also use the fork option which will for a new JVM. You then use the maxHeap option to control the heap size.

Looking at the docs is seams in 3.1.12.3-SNAPSHOT the fork option is true by default. If that is the case for 3.1.12 (or whatever is the exact version you use) and if I'm reading the docs correctly, then you have to configure the maxHeap which defaults to 512.

0
On

as mentioned above, try adjusting the maxHeap value.

what follows is a snippet of maven configuration. this was how i configured spotbugs in order to avoid the out of memory error.

 <reporting>
    <plugins>
        <plugin>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>${spotbugs-maven-plugin.version}</version>
            <configuration>
                <effort>Max</effort>
                <threshold>Low</threshold>
                <maxHeap>2048</maxHeap>
            </configuration>
        </plugin>
    </plugins>
</reporting>