Monday, August 29, 2016

Error with Gradle Build SonarQube Plugin Registering Findbugs Plugin

How to Fix the Error: Unable to register extension org.sonar.plugins.findbugs.FindbugsConfiguration when Running Gradle sonarqube task



Using Gradle, Sonarqube and Findbugs you may get the following error when you try to execute the command:

./gradlew clean build sonarqube


Here is the error:

FAILURE: Build failed with an exception.
* What went wrong:Execution failed for task ':sonarqube'.> Unable to register extension org.sonar.plugins.findbugs.FindbugsConfiguration
* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED


Root Cause


This bug seems to occur when there is a mismatch of versions that don't play nice together.

For instance here are the versions of our stack:

  • Sonar Version: 5.3
  • SonarQube Gradle Plugin:  2.0.1

Update Findbugs plugin on Sonar:


First, we had to update our Sonar server:


Navigate to the Update Center
Navigate to the Sonar Update Center to update the findbugs plugin
Navigate to the Sonar Update Center



Update the findbugs plugin and restart the sonar instance
Update findbugs plugin and restart sonar
Update findbugs plugin

Update your Gradle Dependencies:



Update the sonarqube Gradle Plugin

Update sonarqube dependency

 
dependencies {
     classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1-rc1"
}


Update sonar version
 
sonarqube {
     version='2.1-rc1'
}

Update sonar-findbugs-plugin

dependencies {
     compile: 'org.codehaus.sonar-plugins.java', name: 'sonar-findbugs-plugin', version: '3.2'
}



Update Findbugs

Update findbugs dependency
dependencies {
     compile: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'
}

Update Findbugs version
findbugs {
     toolVersion = "3.0.1"
     ignoreFailures = true
     sourceSets = [ project.sourceSets.main ]
}

Monday, August 22, 2016

Install a Local Instance of AWS DynamoDB



STEP 1:  Press Command+Space and type Terminal and press enter/return key.
STEP 2:  Install Brew(If you don't already have it installed.)  Run this command in the Terminal app.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
and press enter/return key.
Wait for the command to finish.
STEP 3:  Use Brew to install and download dynamoDB so that you can run it locally.
brew install dynamodb-local

Launch your DynamoDB local instance like this:
To have start dynamodb-local now and restart at login as a background service using brew services:
  brew services start dynamodb-local
Or, if you don't want/need a background service you can just run:
  /usr/local/bin/dynamodb-local

You can then access a JS Shell in a browser such as Chrome:
URL to hit the Javascript shell for your locally running DynamoDB instance:
http://localhost:8000/shell/

This is what you will see what you load up your DynamoDB Shell.  If you see this, then you are successfully running a local instance of DynamoDB!

AWS Local DynamoDB Javascript Shell in Browser
AWS Local DynamoDB Javascript Shell in Browser


Common DynamoDB Concepts
  • Table:  A collection of data
  • Items: An item is a group of attributes that is uniquely identifiable among all of the other items.
  • Attributes: An attribute is a fundamental data element, something that does not need to be broken down any further.
  • Primary Key
    • Partition Key:  Composed of one attribute known as the partition key
    • Partition Key and Sort Key: Composite primary key, composed of two attributes.

Datatypes
Scalar
  • Number:  String
    • Example:  "N": "123.45"
  • String:  String
    • Example:  "S": "Hello"
  • Binary:  Base64-encoded binary data
    • Example:  "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"
  • Boolean:  Boolean
    • Example:  "BOOL": true
  • Null:  Boolean
    • Example:  "NULL": true
Multi-value
  • String Set:  Array of Strings
    • Example:  "SS": ["Giraffe", "Hippo" ,"Zebra"]
  • Number Set:  Array of Strings
    • Example:  "NS": ["42.2", "-19", "7.5", "3.14"]
  • Binary Set:  Array of Base64-encoded binary data
    • Example:  "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="]

Document
  • List: array of AttributeValue objects
    • Example:  "L": ["Cookies", "Coffee", 3.14159]
  • Map:  String to AttributeValue object map
    • Example:  "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}}

Tuesday, August 2, 2016

Suppress FindBugs Warnings in a Java and Spring Boot Web Application using Gradle

How to Suppress FindBugs Warnings using Annotations in a +Spring Boot and +Java Application



If your build is breaking because of a FindBugs issue and it is a false-positive or you are unable to resolve the issue because of other considerations, you can add an Annotation to ignore the Findbugs warning.


Update your Gradle Dependencies


You will want to add the following compile time dependency to your build.gradle file.

compile group: 'findbugs', name: 'findbugs', version: '1.0.0'

dependencies {

    compile group: 'findbugs', name: 'findbugs', version: '1.0.0'
}


Get the Findbugs Issue ID

You will need a specific ALL_CAPS identifier so that FindBugs knows what bug to ignore.


Locate the FindBugs Report


In your build message, you will see a link to the findbugs report:



You can also find the report in your build artifact.  Right-click and open in your preferred browser to view file.
find bugs html report in build artifact
Open the findbugs html report from the build directory


Open the FindBugs Report


Once you have it, open the Findbugs HTML report in a browser.  It should look like the following.

findbugs html report for java issues
Find Bugs HTML Report

Get the FindBugs identifier


Copy and paste the FindBugs identifier.  It should be in ALL_CAPS.

You will use the annotation like this:
@SuppressWarnings("OUT_OF_RANGE_ARRAY_INDEX")

Add the Annotation to Your Code


Be sure that the correct findbugs SuppressWarnings annotation is being used.

import edu.umd.cs.findbugs.annotations.SuppressWarnings;


Add Suppress warnings annotation


Add this Suppress warnings annotation above the offending line of code.  There are multiple versions of this annotation.

Be sure to use the specific FindBugs issue ID as a parameter in the annotation.


Be sure to use the annotation specific to findbugs in the package edu.umd.cs.findbugs.annotations.

Suppress warnings annotation
Use the edu.umd.cs.findbugs.annotation version of @SuppressWarnings


This is the annotation you will want to add above the offending line of code.

@SuppressWarnings("OUT_OF_RANGE_ARRAY_INDEX")



Re-run the Build to Verify that the Warning is being Suppressed


You want to ensure that the warning is being ignored correctly.  You may want to add a TODO as well if you intend to fix the issue at a later point as well or at least track the issues you are suppressing in some way.

Your build should run successfully without issuesmoving forward now.



Further info: