Maven Golang build is not scanning Go-ThrowExceptions

Exception or error:

We are using maven to build Golang projects, because we are a mixed-language shop and maven is the current standard for builds.

Our first Go application is a set of services serving a Vue project.

The jenkins file calls mvn sonar:sonar like this:

    stage('Sonar') {
        steps {
            echo 'Building Sonar'
            withSonarQubeEnv('Sonar') {
                // requires SonarQube Scanner for Maven 3.2+
                withMaven(
                        maven: 'Maven 3.5.3',
                        globalMavenSettingsConfig: 'GlobalSettingsRepo',
                        jdk: 'Java 8 Oracle',
                        options: [
                                artifactsPublisher(disabled: true),
                                jacocoPublisher(disabled: true)]) {
                    sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar -U'
                }
            }
        }
    }

I have updated both the parent pom and the pom inside the Go folder to include:

<dependencies>
    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.4.0.905</version>
    </dependency>
    <dependency>
        <groupId>org.sonarsource.go</groupId>
        <artifactId>sonar-go-plugin</artifactId>
        <version>1.0.0.1404</version>
    </dependency>
</dependencies>

I have also hard-coded GOPATH to my Go folder in the environment variables.
However, when I run the build, sonar scanner ONLY scans the xml files in the project. If I run sonar scanner from the command line, it analyzes both the Go code and the Vue code.

Any suggestions?

How to solve:

Apparently, sonar-scanner will analyze your entire project structure by default and requires explicit excludes to skip directories that obviously shouldn’t be analyzed, like node_modules.

Maven sonar plugin expects you to explicitly enumerate your source directories. I placed the following lines in the child pom.xml files and it worked the way I expected.

Golang pom.xml:

<properties>
    <sonar.sources>src/go</sonar.sources>
</properties>

Vue pom.xml:

<properties>
    <sonar.sources>src/views,src/components,src/assets/js,src/assets/css</sonar.sources>
</properties>

Leave a Reply

Your email address will not be published. Required fields are marked *