spotbugs / spotbugs-maven-plugin

Maven Mojo Plug-In to generate reports based on the SpotBugs Analyzer
https://spotbugs.github.io/spotbugs-maven-plugin/
Apache License 2.0
69 stars 51 forks source link

Maven build in multi module project #252

Closed AlexSWeiss closed 3 years ago

AlexSWeiss commented 3 years ago

Hi! 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.

welcome[bot] commented 3 years ago

Thanks for opening your first issue here! :smiley: Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

hazendaz commented 3 years ago

@AlexSWeiss Based on your example runs you have not ran the project to completion. Compilation alone isn't enough. Please try maven clean install which will ensure its loading it to your cache.

hazendaz commented 3 years ago

I would also add you are missing some key data here such as showing that it was actually this plugin that complained. That error generally happens from my experience much earlier in a build. Also are you in apache org? That pull seems a big odd for a general user, not corporate as its publich but it looks like some old items. You may want to make sure you are connected to maven central or corporate repository.

AlexSWeiss commented 3 years ago

@hazendaz 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
hazendaz commented 3 years ago

@AlexSWeiss This shows that your build is running out of memory. That is not a normal condition. You can supply more member to maven but typically that is extremely rare. You may want to ensure you have enough memory on the machine you are using.

AlexSWeiss commented 3 years ago

Followed suggestion from stackoverflow theme: use mvn clean install and change to Xmx1024m. Got following error after executing mvn spotbugs:spotbugs -pl :%X:

[ERROR] Failed to execute goal com.github.spotbugs:spotbugs-maven-plugin:4.0.4:spotbugs (default-cli) on project myProject: Execution default-cli of goal com.github.spotbugs:spotbugs-maven-plugi n:4.0.4:spotbugs failed: Java returned: 1 -> [Help 1]
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148) at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at 
org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)

Also Tried to execute comand mvn spotbugs:spotbugs on hole project at got this error:


[ERROR] Failed to execute goal com.github.spotbugs:spotbugs-maven-plugin:4.0.4:spotbugs (default-cli) on project myProject: Execution default-cli of goal com.github.spotbugs:spotbugs-maven-plugi n:4.0.4:spotbugs failed: Timeout: killed the sub-process -> [Help 1]
AlexSWeiss commented 3 years ago

Resolve issue by adding next to my pom.xml:

    <configuration>
    <effort>Max</effort>
    <threshold>Low</threshold>
    <failOnError>false</failOnError>
        <maxHeap>1024</maxHeap>
    </configuration>
hazendaz commented 3 years ago

Cool! Glad you got it working.