Rahul Singh
Rahul Singh

Reputation: 21

Gradle Build error while using Sonarqube local-plugin from file system

I am trying to use the plugin for sonarqube scanner in my gradle build . Due to the certificate issue It can neither be downloaded from the internet nor from the Nexus repository where the other plugins are usually placed in our environment.

build.gradle

buildscript {
    dependencies {
      classpath files ("../../thirdparty/sonarqube-gradle-plugin-3.1")
                 }
             }

apply plugin: "org.sonarqube"

While executing the build, I am getting the error :

line: 12 * What went wrong:\n A problem occurred evaluating root project 'custom-extensions'.\n> Plugin with id 'org.sonarqube' not found.

am I doing it correctly and how can this be fixed?

Upvotes: 1

Views: 1386

Answers (1)

raspy
raspy

Reputation: 4261

According to the plugin documentation and the description of a flat directory resolver I would make it like this:

buildscript {
  repositories {
    flatDir {
      dirs "../../thirdparty/sonarqube-gradle-plugin-3.1"
    }
  }
  dependencies {
    classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1"
  }
}

apply plugin: "org.sonarqube"

Edit:

sonarqube-gradle-plugin depends on sonar-scanner-api and both of them need to be loaded. When using a flatDir resolver, POMs are not consulted and this dependency cannot be discovered automatically. In this case you would need to explicitly depend on sonar-scanner-api as well:

buildscript {
  repositories {
    flatDir {
      dirs "thirdparty/sonarqube-gradle-plugin-3.1"
    }
  }
  dependencies {
    classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1"
    classpath "org.sonarsource.scanner.api:sonar-scanner-api:2.16.0.226"
  }
}

Your 3rd party directory would need to include both jars; POMs are not needed since they are not consulted anyway:

$ find thirdparty/ -type f
thirdparty/sonarqube-gradle-plugin-3.1/sonar-scanner-api-2.16.0.226.jar
thirdparty/sonarqube-gradle-plugin-3.1/sonarqube-gradle-plugin-3.1.jar

As an alternative approach you can recreate Maven hierarchy locally so that dependencies are parsed automatically. This includes more directories and files, but can be easier to maintain in the long run (if any new dependencies arise it would be sufficient to update the directory contents without altering build.gradle):

buildscript {
  repositories {
    maven {
      url "file://${projectDir}/thirdparty"
    }
  }
  dependencies {
    classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1"
  }
}

apply plugin: "org.sonarqube"

This would require to recreate all the required files and directories:

$ find thirdparty/ -type f
thirdparty/org/sonarsource/parent/parent/55/parent-55.pom
thirdparty/org/sonarsource/scanner/api/sonar-scanner-api/2.16.0.226/sonar-scanner-api-2.16.0.226.jar
thirdparty/org/sonarsource/scanner/api/sonar-scanner-api/2.16.0.226/sonar-scanner-api-2.16.0.226.pom
thirdparty/org/sonarsource/scanner/api/sonar-scanner-api-parent/2.16.0.226/sonar-scanner-api-parent-2.16.0.226.pom
thirdparty/org/sonarsource/scanner/gradle/sonarqube-gradle-plugin/3.1/sonarqube-gradle-plugin-3.1.jar
thirdparty/org/sonarsource/scanner/gradle/sonarqube-gradle-plugin/3.1/sonarqube-gradle-plugin-3.1.pom

Upvotes: 0

Related Questions