Sonarqube gradle analyzing project, task not found in root project - gradle

Analysing project with this command
.\gradlew sonarqube \ -Dsonar.host.url=http://my.url \ -Dsonar.login=login --stacktrace
Getting this error
org.gradle.execution.TaskSelectionException: Task '\' not found in root project 'JavaLint'
And here is my gradle file
plugins {
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'eclipse'
archivesBaseName = 'JavaLint'
version = '0.1-SNAPSHOT'
mainClassName = 'Main'
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Main-Class': 'com.test.Run'
}
}
sourceSets {
main {
java {
srcDirs 'src'
}
}
}
dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'org.jsoup', name: 'jsoup', version: '1.11.2'
compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'log4j', name: 'log4j', version: '1.2.16'
}
Stack trace
I don't understand what am i supposed to do with it.

It looks like you're using cmder (it's so beautiful) which means you're on Windows. For Windows you'll want to provide the arguments to gradle as follows
./gradlew sonarqube -D "sonar.projectKey=<your_project_name>" -D "sonar.host.url=http://localhost:9000" -D "sonar.login=<your_project_token>"

Thanks to the accepted answer by #ka whosyour above,I got my answer too.
Ok let me mention the details of how I was doing for an Android project in Android Studio and what I figured out after my research.
From the command generated by the Sonar Dashbaord, it is
./gradlew sonarqube \-Dsonar.projectKey=LetsGo \-Dsonar.host.url=http://localhost:9000 \-Dsonar.login=53689e9ceab73b3e8a76007d7953af3e9e2b2052
But, for Windows machine it should actually be:
gradlew sonarqube -Dsonar.projectKey=LetsGo -Dsonar.host.url=http://localhost:9000 -Dsonar.login=53689e9ceab73b3e8a76007d7953af3e9e2b2052
This worked like a charm for me.
Notice the Backwards slashes \ which are not needed on the windows machine.
Also, ./gradlew works in mac and gradlew on windows

Make sure first the directory contains gradle.build.
The command for windows :
./gradlew sonarqube -D "sonar.projectKey=your_sonarqube_key" -D "sonar.host.url=http://localhost:9000" -D "sonar.login=your_sonarqube_token"
This has worked for me as expected.

Use it like that in windows Terminal:
.\gradlew sonarqube -Dsonar.host.url=http://my.url -Dsonar.login=login --stacktrace
After that ,you will find the project already in the SonarQube server.

Related

I'm running into dependency issues trying to run an unfamilliar gradle build that I believe worked on an older version of gradle

I've been put into the unfortunate situation where I need to deploy a gradle build on a time crunch when I have never worked with it before. I believe this worked previously but on an older version of gradle that I am unable to roll back to.
I'm running Gradle 7.1 and am receiving this error message:
Could not find method compile() for arguments [{group=org.slf4j,
name=slf4j-api, version=1.7.21}] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
This is the build.gradle file
allprojects {
ext.springVersion="4.2.0.RELEASE"
ext.slf4jVersion="1.7.10"
ext.springDataVersion = "1.8.0.RELEASE"
ext.hibernateVersion = "4.3.9.Final"
ext.springSecurityVersion = "4.2.0.RELEASE"
ext.springDataMongoDBVersion = "1.7.0.RELEASE"
ext.mysqlConnectorVersion = "5.1.13"
}
subprojects {
apply plugin: 'java'
apply plugin : 'eclipse-wtp'
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'com.aet.accel'
version = '1.0.0'
repositories {
mavenLocal()
mavenCentral()
maven{url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"}
maven{url "https://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/"}
}
dependencies {
// logging
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5'
compile "org.apache.logging.log4j:log4j-core:2.5"
compile "org.apache.logging.log4j:log4j-api:2.5"
}
}
Any sort of assistance is very much appreciated, as I am very out of my depth on this one. Thank you for taking a look.
compile has been deprecated, so for libraries use api or implementation

Unable to pass argument from gradle command line to Spring project (not Boot)

I am developing Spring project.
I would like to load credentials from the command line not storying them in the code. I'm trying to execute this gradle command
gradlew build -Dspring.datasource.username=tester
and when I startup the Spring project, the program stops on a breakpoint and I see whether variable is declared or not. I have tried using -P instead of -D but it still didn't help.
I deploy the spring app remotely using bmuschko plugin I've tried to use, but also without success. I checked in java code Properties by using System.getProperties() and Environment object supported by Spring.
gradlew cargoredeployremote -Dspring.datasource.username=tester
Application properties are loaded succesfully.
IMPORTANT: I saw many tutorials how to make it but using Spring Boot I use just selected components from Spring.
For instance: http://nixmash.com/post/passing-arguments-to-spring-boot - this doesn't work in my case because I have no bootRun task.
Any ideas? Am I missing something in my steps?
Here is my build.gradle
group 'example'
version '1.0.0'
apply plugin: 'application'
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'com.bmuschko.cargo'
apply plugin: 'org.liquibase.gradle'
compileJava.options.encoding = 'UTF-8'
mainClassName = 'api.optic.config.WebAppInitializer'
sourceCompatibility = 1.8
buildscript {
repositories{
jcenter()
mavenCentral()
}
dependencies{
classpath 'com.bmuschko:gradle-cargo-plugin:2.2.3'
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-RC3'
classpath 'org.liquibase:liquibase-core:3.4.1'
classpath "org.liquibase:liquibase-gradle-plugin:1.2.4"
classpath "mysql:mysql-connector-java:5.1.13"
}
}
project.ext {
springVersion = "4.3.6.RELEASE"
junitVersion = "5.0.0-RC3"
}
repositories {
mavenCentral()
}
dependencies {
compile "org.springframework:spring-core:${springVersion}"
compile "org.springframework:spring-context:${springVersion}"
compile "org.springframework:spring-context-support:${springVersion}"
compile "org.springframework:spring-beans:${springVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "org.springframework:spring-webmvc:${springVersion}"
compile "org.springframework:spring-orm:${springVersion}"
compile "org.springframework:spring-oxm:${springVersion}"
compile "org.springframework:spring-jdbc:${springVersion}"
compile "org.springframework:spring-test:${springVersion}"
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.38'
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.6'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.2'
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.0.pr2'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8', version: '2.9.0.pr2'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.0.pr2'
compile 'javax.servlet:javax.servlet-api:3.1.0'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
cargo {
containerId = 'tomcat8x'
port = 8080
deployable {
context = 'example'
}
remote {
hostname = 'host.name.com'
username = 'tomcat'
password = 'pass'
}
Basically were 2 issues
1. Name mismatch: in application.properties the name inside the ${} was different than this provided from command-line
Solution:
application.properties
spring.datasource.username=${username}
and in gradle command-line
gradle build -Pusername=tester
2. Dot issue with gradle:
Can't put
gradle build -Pspring.datasource.username=tester
even if you have in application.properties
spring.datasource.username=${spring.datasource.username}
because you get an exception:
Execution failed for task ':processResources'.
Could not copy file '.\src\main\resources\application.properties' to '.\build\resources\main\application.properties'.
Solution:
Instead of dots use _ sign
gradle build -Pspring_datasource_username=tester
and in Application properties
spring.datasource.username=${spring_datasource_username}

Error in building a jar file that uses stanford-corenlp as dependency using gradle

I am writing a very simple program that uses stanford-corenlp. I am building my jar using gradle. I have Java 1.8 and stanford-corenlp version 3.6.
While building, it generates this error
FAILURE: Build failed with an exception.
What went wrong: A problem occurred evaluating root project 'StanfordCoreNLPTest'.
java.lang.StackOverflowError (no error message)
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 5.153 secs
Dependency for core nlp is specified in my gradle build file as
dependencies {
compile 'edu.stanford.nlp:stanford-corenlp:3.6.0'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.6', classifier: 'models'
}
I would very much appreciate any help.
This is a gradle build file with which I have successfully built Java applications with stanford corenlp:
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
repositories {
mavenCentral()
}
dependencies {
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.6.0'
compile group: 'edu.stanford.nlp', name: 'stanford-corenlp', version: '3.6.0', classifier: 'models'
}
Note that:
CoreNLP 3.6.0 requires Java 8. So I put source and target compatibility to 1.8
According to the official instructions to build with maven, you need 2 include statements for stanford-corenlp and in one of them you put classifier models. The above gradle file does that.

Can I remove the 'jar' task in gradle build?

When I use the code below, a file of jar will generate after gradle build.
apply plugin 'java'
Is there any settings won't generate the file of jar??
I can write a custom plugins,but the code below was wrong.
dependencies {
compile project(':crm.common')
testCompile group: 'junit', name: 'junit', version: '4.12'
}
I want find a way that donot generate the file of jar.
And can run compile in dependencies.
Is there any way can do that???
You can do that by 2 ways:
explicitly exclude the jar task from execution:
gradle build -x jar
disable the jar task in build.gradle:
apply plugin: 'java'
jar.enabled = false
This worked for me:
configurations.archives.with {
artifacts.remove artifacts.find { it.toString().contains("jar") }
}

could not resolve all dependencies for configuration ':compile'

To study Gradle I am using the book Gradle in action.
There was an example of dependency definition.
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
But when I do in console gradle build I've got an error
What is the problem? My whole .gradle file looks like this
apply plugin: 'java'
dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
You did not tell Gradle where to find commons-lang3 library. Easy fix is to add the following to your build script:
repositories {
mavenCentral()
}
Of course you can find this piece of information in documentation - http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10608
I was facing this same issue. I fixed it by using local gradle distribution instead of the default gradle wrapper. This is how it goes, make sure that you have Gradle installed and setup(PATH variable).
Open IntelliJ. Goto File->setting->Build, Exec, Deployment->Build tools->Gradle and use local gradle distribution and add your Gradle Home. Apply changes and try to run it now.

Resources