Skip to content

Step 1 run the spotbugs check -> Step 2 run some custom script on the result of the check -> Step 3 publish to website only if step 2 is ok #1039

@patpatpat123

Description

@patpatpat123

Hello team,

I would like to reach out with a question/issue if possible.


What I am trying to do:

We have a CI pipeline where spotbugs is a crucial part.

The pipeline has three steps.

Step 1 -> runs mvn clean install spotbugs:spotbugs

The goal of step 1 is to analyze the code and generate a report


Step 2 -> This step depends on step 1 (cannot happen without step 1)

Step 2 is a custom script that will parse this spotbugs report file.

We have some custom in-house parsing rules, parsing the spotbugs report. To keep the question light, I am going to omit the script.

If some bugs of interest are found, the script will start sending emails, page someone, etc.

If some bugs of interest are found. This step will terminate and kill the pipeline. (There is no need to proceed).

If no spotbugs issues of interest are found, or no spotbugs issues at all, we will go to step 3.


Step 3 -> This step only happens if steps 1 and 2 are good.

At this point, we publish a website via maven site using mvn -site

The spotbugs report in the website might be all clean (no issues at all), or contain some spotbugs issues that are not of interest (because if there were issues of interest, the previous step would catch it and we will not go to this step)

The caveat is that step 3 should not happen before step 2 (we do not wish to publish a website that can contain spotbugs issues of interest)


To achieve the above, we tried three different approaches:

Approach 1: configure spotbugs plugin in the maven build section only

Approach 2: configure spotbugs in the maven report section only

Approach 3: configure spotbugs in both the maven build and report section.

Below are the results for each approach:


Approach 1: configure spotbugs plugin in the maven build section only

   <build>
        <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.9.3.0</version>
                <configuration>
                    <outputDirectory>target/reports/findbugs</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.21.0</version>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.9.0</version>
            </plugin>
        </plugins>
    </reporting>

we run for step 1 : mvn package spotbugs:spotbugs
and for step 3: mvn site

Result 1:

we can see in the logs of step 1 (happy):

[INFO] --- spotbugs:4.9.3.0:spotbugs (default-cli) @ question ---
[INFO] Fork Value is true
[INFO] Done SpotBugs Analysis....

issue:

But for step 3, we do NOT see the report in the website


Approach 2: configure spotbugs in the maven report section only

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.21.0</version>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
             <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.9.3.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.9.0</version>
            </plugin>
        </plugins>
    </reporting>

Issue, this yield:

[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 (/root/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

Approach 3: configure spotbugs in both the maven build and report section.

   <build>
        <plugins>
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.9.3.0</version>
                <configuration>
                    <outputDirectory>target/reports/findbugs</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.21.0</version>
            </plugin>
        </plugins>
    </build>

<reporting>
        <plugins>
             <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.9.3.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.9.0</version>
            </plugin>
        </plugins>
    </reporting>

Approach 3 WORKS!

Couple of observations however:

It seems there are a lot of duplications

Duplication 1: the plugin needs to be present in both sections
Duplication 2: it seems the scan is run twice, as we are seeing this logs

logs from Step 1:

[INFO] --- spotbugs:4.9.3.0:spotbugs (default-cli) @ question ---
[INFO] Fork Value is true
[INFO] Done SpotBugs Analysis....

logs from Step 3:

[INFO] Configuring report plugin spotbugs-maven-plugin:4.9.3.0
[INFO] Detected 1 report for spotbugs-maven-plugin:4.9.3.0: spotbugs

[INFO] Fork Value is true
[INFO] Done SpotBugs Analysis....

[INFO] Generating "SpotBugs" report      --- spotbugs-maven-plugin:4.9.3.0:spotbugs

  • Question:

What I am trying to achieve is this three-step process.
I do believe it is possible. And hopefully, you find the goal is fair enough.

May I ask if I did something wrong in either approach 1 or approach 2 as it is not working?

Is there a way to remove the duplication from approach three and yet still get the correct result?

Thank you for your time reading me (it was pobably a bit long, but I wanted to back my claims with data and facts).

Good day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions