We have a pretty standard web project using Java, which contains also some javascript code in the standard src/main/webapp folder. We are using Gradle 2.14 as our build tool.
We have just installed a brand new Sonarqube 6.0.1 on a fresh server, checked that both the Java and Javascript plugins are installed, and modified the build.gradle file as recommended on the Sonarqube documentation:
plugins {
id 'org.sonarqube' version '2.0.1'
}
sonarqube {
properties {
property 'sonar.projectName', 'Our-Project'
property 'sonar.projectKey', 'com.ourcompany:our-project'
}
}
This doesn't work as expected: the java code is analyzed correctly and we can browse the results on sonar, but the javascript code isn't analyzed.
What are we doing wrong? Thanks.
I have managed to fix our issues by adding this property inside the sonarqube block:
property 'sonar.sources', 'src/main'
Are you sure the sonar.sources is including the js files in the analysis? Can you add the module's gradle config? The file above looks like the app level gradle file. You should have at least one module for your app that also has a gradle file.
Android Studio Project Structure
You need to add the sources to the module's gradle file. Here's an example:
project(":app") {
sonarqube {
properties {
property "sonar.analysis.mode", "publish"
property "sonar.sources", "src/main/java"
property "sonar.java.binaries",
"build/intermediates/classes/debug"
property "sonar.junit.reportsPath",
"build/test-results/developDebug"
property "sonar.android.lint.report",
"build/outputs/lint-results-developDebug.xml"
property "sonar.test", "src/test/java"
}
}
}
Related
I'm trying to create a custom source set and mark its contents in Intellij Idea as a Test Sources Root. I tried to use idea plugin and do it according to the gradle official website but it is not clear for me how it works.
First of all the documentation specifies the following configuration setup
idea {
module {
testSources.from(sourceSets["intTest"].java.srcDirs)
}
}
When I try to use it i receive Unresolved reference: testSources. Where is it coming from?
Then I tried to use:
idea {
module {
testSourceDirs = intTest.java.srcDirs
}
}
it works fine as long as I use only Java. After applying Kotlin plugin however, both kotlin and java + resources folder are again treated as Sources Root not Test Sources. To fix that I had to change from:
testSourceDirs = intTest.java.srcDirs
to:
testSourceDirs = intTest.kotlin.srcDirs
and now all folders are Test Source Root again. Since kotlin.srcDirs also includes java.srcDirs it looks like you have to specify all, otherwise it is ignored...
Now the real issue came when I used gradle-avro-plugin. Applying it made my folders marked as Sources Root again. I believe it is because it adds another avro directory, but just to main source set.
Does anyone know how to make it marked as Test Sources having both kotlin and avro plugin applied? Am I doing something wrong here? Beacause this beheviour seems to be buggy in the first place.
Tested with:
IntelliJ IDEA 2022.3.1 (Ultimate Edition)
Gradle 6.8.3 and 7.4.2
Plugin id("com.github.davidmc24.gradle.plugin.avro") version "1.5.0"
Plugin kotlin("jvm") version "1.7.0"
I have my sonarqube configured the following way on a multi-module gradle project.
sonarqube {
properties {
property("sonar.projectKey", "key")
property("sonar.organization", "org")
property("sonar.host.url", "https://sonarcloud.io")
}
}
This configuration is on the root build.gradle.kts.
I now have a integration test folder that I added using the jvm-test-suite plugin and I want these sources to show up as well on Sonarqube.
I've added this config:
property("sonar.tests", "src/test, src/integrationTest")
But made no difference. They don't show up.
Any ideas? Thanks
We have a multi-module project in gradle. We have a "data" module that needs to be compiled (simple java 11 app) then run.
When we run java -jar data.jar after compiling the data module source is generated into the "webapp" module. With this generated source code we are now able to build the webapp module.
I am new to Gradle and struggling to figure out how do achieve this properly. I am especially concerned if I do it wrong I will make build caching fail.
Note: I am using Kotlin with Gradle 7.5.
The answer appears to be to create a custom configuration which produces a different artifact than the default.
task(taskJarGenerated, Jar::class) {
group = groupJooq
dependsOn(taskCompileGeneratedSource)
inputs.dir("$projectDir/build/classes/java/main")
outputs.file("${projectDir}/build/libs/data-1.0.jar")
from("$projectDir/build/classes/java/main")
}
artifacts {
add("generatedDbDataJar", tasks[taskJarGenerated])
}
Then you can reference this custom configuration "generatedDbDataJar" in other projects like this:
dependencies {
implementation(project(":data","generatedDbDataJar"))
}
I'm trying to apply precompile script gradle.kts file (gradle.kts script is put in buildSrc/main/java. everything work normally except that i can not add a plugin with version. for example my test.gradle.kts
plugins {
id("io.gitlab.arturbosch.detekt") version "1.1.1"
}
but always got the error
Invalid plugin request [id: 'io.gitlab.arturbosch.detekt', version: '1.1.1']. Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin 'io.gitlab.arturbosch.detekt' is an implementation dependency of project ':buildSrc'.
And also I cannot the class to configure extension
For example, this normally configuration is not working
configure<DetektExtension>
How can we specify plugin version in precompile script? and how can we configure the plugin?
Without being able to see your build structure and file tree I can only answer based on how I'm understanding your question. Based on the error message you are receiving, you should be declaring the plugin dependency in the project level build.gradle.kts:
plugins {
id("io.gitlab.arturbosch.detekt") version "1.1.1"
}
Then in your buildSrc/build.gradle implement it like so:
plugins {
`io.gitlab.arturbosch.detekt`
}
Gradle has samples on GitHub, from which I drew this example, here:
https://github.com/gradle/kotlin-dsl-samples/tree/master/samples/multi-kotlin-project-with-buildSrc
I have a custom gradle.kts script I am building that will do our maven publishing for all of our various modules to our sonatype repository, but encountering a strange error. Here are the contents of my maven-deploy.gradle.kts file:
plugins {
`maven-publish`
signing
}
publishing {
//expression 'publishing' cannot be invoked as a function.
//The function invoke() is not found
}
I can run tasks and whatnot within the maven-deploy.gradle.kts file fine, but trying to use the publishing function from the gradle documentation is proving to be impossible. Any ideas? I'm using gradle version 4.10.3 (I need Android support). The maven-deploy.gradle.kts file is in buildSrc/src/main/kotlin and is being added by id("maven-deploy") in my main project's build.gradle.kts file.
This happens because Gradle only imports the generated type-safe accessors for Gradle Kotlin DSL into the main build script, but not into script plugins:
Only the main project build scripts have type-safe model accessors. Initialization scripts, settings scripts, script plugins (precompiled or otherwise) do not. These limitations will be removed in a future Gradle release.
See Understanding when type-safe model accessors are available
In the script you mentioned, you can access the publishing extension dynamically, for example, using configure<PublishingExtension> { ... }:
import org.gradle.api.publish.PublishingExtension
plugins {
`maven-publish`
signing
}
configure<PublishingExtension> {
// ...
}
This is described here: Project extensions and conventions
UPD: Gradle 5.3 RC1 seems to add a possibility to use the generated extensions in script plugins.