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

Getting error while running spotbugs target in multi-module project #323

Closed noorul closed 2 years ago

noorul commented 3 years ago

I have the below pom.xml in the parent folder and the command mvn spotbugs:check gives an error. The same plugin works with a simple project without modules.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>bar.foo.gravity</groupId>
    <version>1.0.0-${release.version}</version>
    <artifactId>common-java-libs</artifactId>
    <packaging>pom</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>streamingcommon</module>
        <module>metricscommon</module>
        <module>barcommon</module>
    </modules>
    <build>
        <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.2.0</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.2.3</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.2</version>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>8.41.1</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <consoleOutput>true</consoleOutput>
                    <configLocation>checkstyle.xml</configLocation>
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>2.10.1</version>
                <configuration>
                    <formats>
                        <!-- you can define as many formats as you want, each is independent -->
                        <format>
                            <!-- define the files to apply to -->
                            <includes>
                                <include>*.md</include>
                                <include>.gitignore</include>
                            </includes>
                            <!-- define the steps to apply to those files -->
                            <trimTrailingWhitespace />
                            <endWithNewline />
                            <indent>
                                <spaces>true</spaces>
                                <spacesPerTab>4</spacesPerTab>
                            </indent>
                        </format>
                        <format>
                            <includes>
                                <include>**/*.xml</include>
                                <include>**/*.xsd</include>
                            </includes>
                            <excludes>
                                <exclude>**/target/**</exclude>
                            </excludes>
                            <eclipseWtp>
                                <type>XML</type> <!-- specify the WTP formatter type (XML, JS, ...) -->
                                <files> <!-- specify the configuration for the selected type -->
                                    <file>${basedir}/xml.prefs</file>
                                </files>
                                <version>4.13.0</version> <!-- optional -->
                            </eclipseWtp>
                        </format>
                    </formats>
                    <!-- define a language-specific format -->
                    <java>
                        <!-- no need to specify files, inferred automatically, but you can if you want -->
                        <!-- apply a specific flavor of google-java-format -->
                        <googleJavaFormat>
                            <version>1.8</version>
                            <style>AOSP</style>
                        </googleJavaFormat>
                    </java>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Error reported

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] streamingcommon                                                    [jar]
[INFO] metricscommon                                                      [jar]
[INFO] barcommon                                                          [jar]
[INFO] common-java-libs                                                   [pom]
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 9.8 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (20 kB at 14 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for common-java-libs 1.0.0-${release.version}:
[INFO] 
[INFO] streamingcommon .................................... SKIPPED
[INFO] metricscommon ...................................... SKIPPED
[INFO] barcommon ...................................... SKIPPED
[INFO] common-java-libs ................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.321 s
[INFO] Finished at: 2021-05-08T01:24:38+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'spotbugs' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/Users/noorul/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
hazendaz commented 3 years ago

I think maven has a bug. Their logic is defined here and I know what you are doing used to work. I tried a few different plugins with maven 3.8.1 and not a one works now unless owned by maven or mojohaus. There isn't anything special they define so I'm not sure if this is just an issue in 3.8.1 or how long its been a problem. To get around it, you can add the following to your settings.xml.

    <pluginGroups>
      <pluginGroup>com.github.spotbugs</pluginGroup>
    </pluginGroups>
hazendaz commented 3 years ago

Other option which does work, add spotbugs to dependency management then it will also just work without having to mess with settings.xml.

noorul commented 3 years ago

@hazendaz Thank you, adding pluginGroups to made it work. But normally we do not have settings.xml inside the source repository. Do you know whether there is an open bug for this?

hazendaz commented 3 years ago

I don't know if any defect is opened but seemed to recall maven changing in recent versions how resolutions worked. You can instead just list spotbugs in dependency management and that will also solve for it.

hazendaz commented 2 years ago

closing as work around present.