Plugin with id 'org.sonarqube' not found - spring-boot

I am trying to implement sonar with gradle for code-coverage measure for my project.
we are using gradle-4.0.1 and sonarqube-6.4 .
when I run gradle sonarqube from command line I get this error-
Plugin with id 'org.sonarqube' not found.
I tried few code changes but no luck, please help.
My build.gradle file is as below-
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.sonarqube'
apply plugin: "jacoco"
apply plugin: "java"
apply plugin: "war"
apply plugin: "org.springframework.boot"
sonarqube {
properties {
property "sonar.projectName","Spring4WebService Code Coverage Demo"
property "sonar.projectKey", "org.sonarqubeJacocoCodeCoverage"
property "sonar.reportPath" , "${project.buildDir}/jacoco/test.exec"
}
}
test{
ignoreFailures = true
}
ext {
jacocoVersion = '0.7.6.201602180812'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
main.java.srcDir "src/main/java"
test.java.srcDir "src/test/java"
}
springBoot {
mainClass = "com.concretepage.config.WebAppInitializer"
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web','com.fasterxml.jackson.core:jackson-databind')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
jacoco{
toolVersion = "${jacocoVersion}"
}
jacocoTestReport {
reports{
html.enabled=true
xml.enabled=true
csv.enabled=true
}
}

Just like the 'org.springframework.boot' plugin, the 'org.sonarqube' plugin does not belong to Gradle. It is a third-party plugin, so you need to add it as a buildscript dependency:
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
Now apply plugin: 'org.sonarqube' should work fine.

In my case it looks like:
plugins {
id 'groovy'
id 'application'
id 'org.sonarqube' version '3.0'
}
repositories {
mavenCentral()
}
sonarqube {
properties {
property "sonar.host.url", "http://sonarqube:9000"
property "sonar.sources", "src"
}
}
tasks['sonarqube'].dependsOn test

Using the plugins DSL specifying a full version (e.g., id "org.sonarqube" version "3.5.0.2730" instead of id "org.sonarqube" version "3.5.0") in the plugins section of build.gradle resolved this issue for me.
Here are examples for plugins DSL and legacy plugin application: https://plugins.gradle.org/plugin/org.sonarqube

Related

Gradle Kotlin : How to convert kotlin2js plugin of groovy build.gradle to build.gradle.kts?

From https://kotlinlang.org/docs/tutorials/javascript/getting-started-gradle/getting-started-with-gradle.html I got the following build.gradle (groovy) script :
group 'org.example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin2js'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
I tried this translation :
group 'org.example'
version '1.0-SNAPSHOT'
buildscript {
extra["kotlinVersion"] = "1.3.61"
repositories {
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlinVersion"]}")
}
}
plugins {
kotlin2js // <= this is incorrect
application
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-js:${extra["kotlinVersion"]}")
}
application {
mainClassName = "io.ipfs.kotlin.MainIpfsKt"
}
gradle emits the following error message
kotlin2js
^ Unresolved reference: kotlin2js
What is the correct translation for apply plugin: 'kotlin2js' ?

Gradle doesn't copy html files into executed jar

build.gradle
buildscript {
ext {
springBootVersion = '2.0.6.RELEASE'
springRestDocsVersion = '2.0.2.RELEASE'
gradleDockerVersion = '1.2'
asciidoctorGradlePluginVersion = '1.5.9.2'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.asciidoctor:asciidoctor-gradle-plugin:${asciidoctorGradlePluginVersion}")
classpath("se.transmode.gradle:gradle-docker:${gradleDockerVersion}")
}
}
plugins {
id "org.springframework.boot" version "2.0.6.RELEASE"
id "org.asciidoctor.convert" version "1.5.9.2"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.asciidoctor.convert'
apply plugin: 'application'
apply plugin: 'docker'
apply from: 'local.gradle'
mainClassName = 'class.path.package.BootApplication'
version = '0.0.3a'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// Standard spring boot packages
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile('org.postgresql:postgresql')
compile('biz.paluch.redis:lettuce:4.4.6.Final')
compile('org.pacesys:openstack4j-core:3.1.0')
compile('org.pacesys.openstack4j.connectors:openstack4j-httpclient:3.1.0')
// Dozer object mapping
compile('net.sf.dozer:dozer:5.5.1')
// Sengrid library
compile('com.sendgrid:sendgrid-java:4.2.1')
compile('org.freemarker:freemarker:2.3.28')
// Cloudant
compile('com.cloudant:cloudant-client:2.9.0')
compile('com.squareup.okhttp3:okhttp-urlconnection:3.4.2')
compile('org.json:json:20171018')
compile('javax.validation:validation-api:2.0.1.Final')
//Swagger2
compile('io.springfox:springfox-swagger2:2.9.2')
compile('io.springfox:springfox-swagger-ui:2.9.2')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.security:spring-security-test')
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc")
testCompile("org.asciidoctor:asciidoctor-gradle-plugin:1.5.9.2")
asciidoctor('org.springframework.restdocs:spring-restdocs-asciidoctor:2.0.2.RELEASE')
}
processResources {
// expand(project.properties)
}
ext {
springCloudVersion = 'Finchley.RELEASE'
snippetsDir = file('build/generated-snippets')
// springRestDocsVersion = '2.0.2.RELEASE'
}
ext['spring-restdocs.version'] = '${springRestDocsVersion}'
test {
outputs.dir snippetsDir
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
}
}
asciidoctor {
// attributes "snippets": snippetsDir
inputs.dir snippetsDir
dependsOn test
}
jar {
dependsOn asciidoctor
from ('${asciidoctor.outputDir}/html5') {
into 'static/apidocs'
}
}
my problem actually in this part:
jar {
dependsOn asciidoctor
from ('${asciidoctor.outputDir}/html5') {
into 'static/apidocs'
}
}
executed jar doesn't copy index.html file executed from asciidoctor into jar and jar executed only without this file
So how i can copy build/asciidoc/html5/index.html from build
folder into executed jar?
Also if i need to use bootJar task so how i can make it include all jar needed into /BOOT-INF/lib/
Your configuration is almost right, but you are customising the wrong task. A Spring Boot fat jar is built with the bootJar task rather than the jar task.
You need to replace jar with bootJar in your build.gradle. This will result in it looking the same as the following example:
bootJar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
This is the configuration that's described in the REST Docs documentation.

Gradle Multimodule Project unable to resolve class of depending sub module

The application works fine in Eclipse. But I am not able to build the application via gradle (gradle clean build)
The structure is like:
financial-calculator (parent)
library
api
api wants to use classes of library
My parent's settings.gradle file:
rootProject.name = 'financial-calculator'
include 'library'
include 'api'
rootProject.children.each { it.name = rootProject.name + '-' + it.name }
The parent build.gradle file:
buildscript {
ext {
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "o.s.b:spring-boot-gradle-plugin:${springBootVersion}"
}
}
allprojects {
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'maven-publish'
group = 'net.hemisoft.financial.calculator'
version = "0.1.0-SNAPSHOT"
}
subprojects {
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile 'o.c.g:groovy'
testCompile 'o.s.b:spring-boot-starter-test'
}
dependencyManagement {
imports { mavenBom("o.s.b:spring-boot-dependencies:${springBootVersion}") }
}
}
project(rootProject.name + '-library') {
dependencies {
compile 'o.s.b:spring-boot-starter'
}
}
project(rootProject.name + '-api') {
dependencies {
compile project (':' + rootProject.name + '-library')
compile 'o.s.b:spring-boot-starter-web'
}
}
The complete small project you will find under link
Thanks for your hints.

Cannot resolve external dependency org.springframework.boot:spring-boot-starter: because no repositories are defined

I have a multibuild project and I am currently just setting it up. Each module naturally each has a gradle.build file that only contains the following:
dependencies {
}
In the main build.gradle file I have want is needed for every module. However when I do a gradle build I get a error saying:
Cannot resolve external dependency org.springframework.boot:spring-boot-starter: because no repositories
are defined. Required by:
project :
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
sourceSets.all { ext.purpose = null }
// Everything in subprojects are applied to all modules
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
test {
useTestNG()
testLogging.showStandardStreams = true
beforeTest { descriptor ->
logger.lifecycle("Running test: " + descriptor)
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Advice
You've defined repositories for subprojects only, but you have to define it in the root project too, because you have a dependencies block there:
dependencies {
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
In your case you can do it by declaring repositories once more out of the subprojects closure:
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
subprojects {
...
}
Or you can define it for all projects:
allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
in that case, you don't need o declare it in subprojects closure
I fixed in Intellij IDEA with these steps.
Go to Settings->Gradle
Under 'Use Gradle from' provide the correct version of Gradle
Gradle JVM I selected as local JAVA_HOME

Unable to start EmbeddedWebApplicationContext - not a web app

Here is the build.gradle file. I have removed comments and sensitive data.
Still receiving the "missing EmbeddedServletContainerFactory Bean" error.
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://plugins.gradle.org" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
classpath("org.jfrog.buildinfo:build-info-extractor-gradle:4.5.4")
classpath("gradle.plugin.de.gliderpilot.gradle.semantic-
release:gradle-semantic-release-plugin:1.3.1")
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
{
exclude module: 'spring-boot-starter-tomcat'
}
runtime files ('/libs/ojdbc8.jar')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
plugins {
id "org.sonarqube" version "2.5"
id "com.gorylenko.gradle-git-properties" version "1.4.17"
id "de.gliderpilot.semantic-release" version "1.3.1"
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'idea'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
group = 'com.usps.informed-delivery'
dependencies {
compile('org.springframework.boot:spring-boot-starter-activemq')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-batch')
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-data-cassandra')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-integration')
compile('org.springframework.batch:spring-batch-integration')
compile('org.springframework.integration:spring-integration-xml')
compile('org.springframework.integration:spring-integration-mail')
compile('org.springframework.integration:spring-integration-test')
compile('org.slf4j:slf4j-api')
compile('org.springframework.integration:spring-integration-java-dsl')
compile("org.springframework:spring-oxm")
compile("joda-time:joda-time")
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
compile('org.liquibase:liquibase-core')
compile('libs/ojdbc8.jar')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.batch:spring-batch-test')
testCompile('org.springframework.integration:spring-integration-test')
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = 'http:whatever'
publish {
repository {
if (version.toString().endsWith("-SNAPSHOT")) {
repoKey = 'snapshots'
} else {
repoKey = 'releases'
}
username = ""
password = ""
}
defaults {
publications('mavenJava')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
resolve {
repoKey = 'jcenter'
username = ""
password = ""
}
}
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "readers-digest-generator"
property "sonar.projectName", "Readers Digest Generator"
}
}
Posting the build.gradle file per request. I have tried to resolve by putting
spring.main.web-environment-=false in aplication.properties file and app.setWebEnvironment(false) in BatchApplication.java
Spring Boot assumes it's a web app unless you configure it otherwise. The documentation (found here https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-boot-application.html#howto-create-a-non-web-application) illustrates that you can either configure your application to not be a web app either programatically via calling SpringApplication#s setWebEnvironment(false) or via setting the property spring.main.web-environment=false

Resources