Preface
The previous article learned sonar, this article to explain sonar runner. The difference is that sonar runner is uploading the analyzed data to the database, and sonar is using various methods to organize the data in the database into different forms for the user. So sonar relies on sonar runner, and no data can be displayed.
Knowledge points
1.sonar version and compatibility
Gradle The version of Sonar runner that is used by default is 2.3, and this version supports Sonar version 3.0 and higher. But if you have to support the 3.0 before (or do not have this happen, brave to embrace the new things bad), it needs to be configured.
2.plugin Identification
Apply plugin: ' Sonar-runner '
3. How to perform
Gradle Sonarrunner
configuration of the 4.Sonar runner
Similar to Sonar's configuration, the configuration is not the same, the configuration is in the form of Key/value, and in Sonar is a special property name assignment method.
<pre name= "code" class= "java" >sonarrunner {
sonarproperties {property
"Sonar.host.url", "/HTTP// Localhost:9002/"Property
" Sonar.jdbc.url "," Jdbc:mysql://localhost:3306/sonar "
Sonar.jdbc.driverClassName "," Com.mysql.jdbc.Driver "Property
" Sonar.jdbc.username "and" sonar "property
" Sonar.jdbc.password "," Sonar "
}
}
5. Version Configuration
In the 1th section, the Sonar runner default version is 2.3, and of course you can modify it by using the following statement.
Sonarrunner {
toolversion = ' 2.3 '//Default
}
6. Multi-Project Construction
Here is similar to Sonar, I will directly post configuration, no longer elaborated.
There are both global and private 2 configurations, you can configure common properties for each subproject, or you can separate them to configure special properties for each subproject.
Set the character encoding for each item to UTF-8
subprojects {
Sonarrunner {
sonarproperties {property
"sonar.sourceencoding", "UTF-8"
}
}
}
Set the language for Project1 to groovy
Project (":p Roject1") {
Sonarrunner {
sonarproperties {property
"Sonar.language", "Grvy"
}
}
}
Set skip quality management for Project2.
Project (":p Roject2") {
Sonarrunner {
Skipproject = True
}
}
7. Custom Sourcesets
Sonar also has these configurations, so a pen has been brought over. (Why are they all configured?)
Sonarrunner {
sonarproperties {
properties["sonar.sources"] + = SourceSets.custom.allSource.srcDirs
properties["sonar.tests"] + = SourceSets.integTest.allSource.srcDirs
}
}
8. More than just Java
Same as Sonar is the ability to analyze other languages. I've already talked about how to set up a language.
9. Controlling the execution of the sonar runner process
Sonar runner, like the test process, is a separate process. You can set the memory of the process and the system properties. To see what properties you can set, you can view the Javaforkoptions class in the API.
Sonarrunner {
forkoptions {
maxheapsize = ' 512m '
}
}