Spot bugs / Maven build in multi module project

4.5k Views Asked by At

During adding spotbugs to my multi module project I've got an issue:
Failed to execute goal on project %X: Could not resolve dependencies for project %X:war:1.0.1-SNAPSHOT: Failure to find %Y. 1-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of apache.snapshots has elapsed or updates are forced -> [Help 1]

Where:
%X - module 1 it depends on module 2 (%Y)
%Y - module 2 (.jar library) needed for module 1 (%X)

perent pom.xml:

    <artifactId>myProj</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>%X</module>
        <module>%Y</module>
    </modules>

       ...

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.github.spotbugs</groupId>
                    <artifactId>spotbugs-maven-plugin</artifactId>
                    <version>4.0.4</version>
                    <dependencies>
                        <!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
                        <dependency>
                            <groupId>com.github.spotbugs</groupId>
                            <artifactId>spotbugs</artifactId>
                            <version>4.1.2</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

child module pom.xml:

<parent>
        <groupId>my.project</groupId>
        <artifactId>myProj</artifactId>
        <relativePath>../pom.xml</relativePath>
        <version>1.0.0-SNAPSHOT</version>
    </parent>

    <artifactId>%X</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>%X</name>

       .....

      <build>
        <finalName>%X</finalName>
        <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
            </plugin>
                       ..........
     </build>

Then I execute commands in next order:
>mvn clean compile - project compiled as normally
>mvn spotbugs:spotbugs - error outputted

Also tried:

  1. Executing clean compile with -U
  2. Deleting artifacts from my local maven repo
  3. Adding plugin only in my child module and executing mvn spotbugs:spotbugs -pl :%X
  4. Step followed next guide [link]
  5. Checked IntelliJ plugin, it works

So the question is: How to start it correctly? :)

P.S. Does spotbugs have some resriction in code analysis? I'm trying to use it on a legacy project so maybe because of that I have troubles
P.S.S. I'v tried it on my other project that has no "childs" and it used (let's say) latest technologies all work corectly.


Updated: Tried execute maven clean install -pl :%Y and now I got other error. Also tried to exclude "apache org" and have same errors Stack-trace:

[INFO] 
[INFO] --- spotbugs-maven-plugin:4.0.4:spotbugs (default-cli) @ myProject ---
[INFO] Fork Value is true
     [java] Exception in thread "main" edu.umd.cs.findbugs.ba.AnalysisException: Exeption was thrown during analysis
     [java]     at edu.umd.cs.findbugs.FindBugs2.lambda$analyzeApplication$3(FindBugs2.java:1125)
     [java]     at java.util.ArrayList.forEach(ArrayList.java:1257)
     [java]     at edu.umd.cs.findbugs.FindBugs2.analyzeApplication(FindBugs2.java:1118)
     [java]     at edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:309)
     [java]     at edu.umd.cs.findbugs.FindBugs.runMain(FindBugs.java:395)
     [java]     at edu.umd.cs.findbugs.FindBugs2.main(FindBugs2.java:1231)
     [java] Caused by: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
     [java]     at java.util.concurrent.FutureTask.report(FutureTask.java:122)
     [java]     at java.util.concurrent.FutureTask.get(FutureTask.java:192)
     [java]     at edu.umd.cs.findbugs.FindBugs2.lambda$analyzeApplication$3(FindBugs2.java:1120)
     [java]     ... 5 more
     [java] Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
     [java]     at java.util.HashMap.resize(HashMap.java:704)
     [java]     at java.util.HashMap.putVal(HashMap.java:629)
     [java]     at java.util.HashMap.put(HashMap.java:612)
     [java]     at java.util.HashSet.add(HashSet.java:220)
     [java]     at java.util.AbstractCollection.addAll(AbstractCollection.java:344)
     [java]     at java.util.HashSet.<init>(HashSet.java:120)
     [java]     at edu.umd.cs.findbugs.ba.deref.UnconditionalValueDerefSet.cleanDerefSet(UnconditionalValueDerefSet.java:407)
     [java]     at edu.umd.cs.findbugs.ba.deref.UnconditionalValueDerefAnalysis.propagateDerefSetsToMergeInputValues(UnconditionalValueDerefAnalysis.java:881)
     [java]     at edu.umd.cs.findbugs.ba.deref.UnconditionalValueDerefAnalysis.meetInto(UnconditionalValueDerefAnalysis.java:728)
     [java]     at edu.umd.cs.findbugs.ba.Dataflow.execute(Dataflow.java:345)
     [java]     at edu.umd.cs.findbugs.classfile.engine.bcel.UnconditionalValueDerefDataflowFactory.analyze(UnconditionalValueDerefDataflowFactory.java:82)
     [java]     at edu.umd.cs.findbugs.classfile.engine.bcel.UnconditionalValueDerefDataflowFactory.analyze(UnconditionalValueDerefDataflowFactory.java:41)
     [java]     at edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:368)
     [java]     at edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:321)
     [java]     at edu.umd.cs.findbugs.ba.ClassContext.getMethodAnalysis(ClassContext.java:995)
     [java]     at edu.umd.cs.findbugs.ba.ClassContext.getUnconditionalValueDerefDataflow(ClassContext.java:837)
     [java]     at edu.umd.cs.findbugs.detect.BuildUnconditionalParamDerefDatabase.analyzeMethod(BuildUnconditionalParamDerefDatabase.java:118)
     [java]     at edu.umd.cs.findbugs.detect.BuildUnconditionalParamDerefDatabase.considerMethod(BuildUnconditionalParamDerefDatabase.java:107)
     [java]     at edu.umd.cs.findbugs.detect.BuildUnconditionalParamDerefDatabase.visitClassContext(BuildUnconditionalParamDerefDatabase.java:91)
     [java]     at edu.umd.cs.findbugs.DetectorToDetector2Adapter.visitClass(DetectorToDetector2Adapter.java:76)
     [java]     at edu.umd.cs.findbugs.FindBugs2.lambda$null$1(FindBugs2.java:1108)
     [java]     at edu.umd.cs.findbugs.FindBugs2$$Lambda$18/1193894341.call(Unknown Source)
     [java]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
     [java]     at edu.umd.cs.findbugs.CurrentThreadExecutorService.execute(CurrentThreadExecutorService.java:86)
     [java]     at java.util.concurrent.AbstractExecutorService.invokeAll(AbstractExecutorService.java:238)
     [java]     ... 4 more

2

There are 2 best solutions below

4
On

Please use mvn clean install, this brings your artifact to the local repository. Because this enables you to:

use (your projects/modules) as a dependency in other projects locally

Rather than mvn clean compile, which only compiles up to the "build output folder" (normally target;) (...and which is probably enough for the IDE, but also omits complete test and package phases :o)

...which makes the error message from spotbugs more comprehensible (it is correct: the %X:war:1.0.1-SNAPSHOT is in no repository (only at the state, at which you last executed install).)

https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html


UPDATE: The only chance, I see, to overcome java.lang.OutOfMemoryError, is to:

Increase memory! (https://spotbugs.github.io/spotbugs-maven-plugin/faq.html#How_do_I_avoid_OutOfMemory_errors, please also notice the "fork" comment.)

Analyzing your stacktrace and the current source code of https://github.com/spotbugs/spotbugs/blob/master/spotbugs/src/main/java/edu/umd/cs/findbugs/ba/deref/UnconditionalValueDerefSet.java#L407, it is:

Set<ValueNumber> valueNumbers = new HashSet<>(vnaFrame.allSlots());

...so no obvious bug, but really just a huge hashset (instantiation/copy), and increasing the memory a fair solution.

0
On

Resolve issue by adding next to my pom.xml:

<plugin>
    <groupId>com.github.spotbugs</groupId>
    <artifactId>spotbugs-maven-plugin</artifactId>
    <version>4.0.4</version>
    ........
        <configuration>
            <effort>Max</effort>
            <threshold>Low</threshold>
            <failOnError>false</failOnError>
            <maxHeap>1024</maxHeap>
        </configuration>
    ........
</plugin>