Using sonarRunner in a multi-project java code base, using gradle, skips classes of exactly one project

I have a multi-module java code base that I use with support

The build works fine, and I can compile and create banks without any problems.

I also use the gradle eclipse plugin and can import the gradle multiproject into eclipse, which means that all subprojects imported into Eclipse are well managed using the java build path.

I use the sonar runner plugin that comes with gradle, and the Sonar version is 3.4.1. I am using the H2 database that comes with Sonar.

This is what I use to configure sonarRunner in the root project in build.gradle :

 apply plugin: "sonar-runner" sonarRunner { sonarProperties { property "sonar.host.url", "http://localhost:9000" property "sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar" property "sonar.jdbc.driverClassName", "org.h2.Driver" property "sonar.jdbc.username", "sonar" property "sonar.jdbc.password", "sonar" } } 

For each subproject, I do this:

 sonarRunner { sonarProperties { property "sonar.projectName", pathToAtgModuleName(path) property "sonar.sourceEncoding", "UTF-8" property "sonar.language", "java" } } 

I set the sonar.projectName property so that the Sonar toolbar can correctly display nested modules. The value of sonar.projectName looks like this: ParentModule.ChildModule.SubChildModule .

The Sonar report works for most but one module. It simply ignores all classes in this module.

My project structure is similar to this (the number of java classes, including inner classes, is on the right):

 RootProj/core 356 RootProj/MyMod 343 RootProj/MyMod/versioned 0 RootProj/MyMod/versioned/catalog 33 RootProj/integration/int1 9 RootProj/integration/int2 7 RootProj/integration/int3 5 RootProj/integration/int4 2 RootProj/integration/int5 17 RootProj/integration/int6 44 RootProj/perf 0 RootProj/REST 12 RootProj/Store 11 RootProj/TestRest 92 RootProj/TestStore 141 RootProj/TestVersioned 1 RootProj/webservices 14 

A module that cannot show any classes is RootProj / MyMod .

For a project where classes are found, the result is as follows:

 18:58:34.016 INFO .sbbProjectModule - ------------- Analyzing RootProj.MyMod.versioned.catalog 18:58:34.019 INFO .bbProjectSettings - Load module settings 18:58:34.859 INFO .sbProfileProvider - Quality profile : [name=RCS_way,language=java] 18:58:34.883 INFO nPluginsConfigurator - Configure maven plugins... 18:58:34.977 INFO org.sonar.INFO - Compare to previous analysis (2013-06-12) 18:58:35.026 INFO org.sonar.INFO - Compare over 5 days (2013-06-07, analysis of 2013-06-05 12:16:12.963) 18:58:35.066 INFO org.sonar.INFO - Compare over 30 days (2013-05-13, analysis of 2013-06-03 15:12:37.359) 18:58:35.133 INFO .bpSensorsExecutor - Initializer ProjectFileSystemLogger... 18:58:35.135 INFO jectFileSystemLogger - Excluded tests: [**/package-info.java] 18:58:35.139 INFO jectFileSystemLogger - Source directories: 18:58:35.140 INFO jectFileSystemLogger - D:\eCommerce\code\R0_3\RootProj\MyMod\versioned\catalog\src 18:58:35.140 INFO .bpSensorsExecutor - Initializer ProjectFileSystemLogger done: 7 ms 18:58:35.185 INFO p.PhasesTimeProfiler - Sensor JavaSourceImporter... 18:58:35.441 INFO p.PhasesTimeProfiler - Sensor JavaSourceImporter done: 256 ms 

This is the result of SonarRunner for this project:

 18:59:24.747 INFO .sbbProjectModule - ------------- Analyzing RootProj.MyMod 18:59:24.748 INFO .bbProjectSettings - Load module settings 18:59:25.164 INFO .sbProfileProvider - Quality profile : [name=RCS_way,language=java] 18:59:25.175 INFO nPluginsConfigurator - Configure maven plugins... 18:59:25.186 INFO org.sonar.INFO - Compare to previous analysis (2013-06-12) 18:59:25.194 INFO org.sonar.INFO - Compare over 5 days (2013-06-07, analysis of 2013-06-05 12:16:12.957) 18:59:25.203 INFO org.sonar.INFO - Compare over 30 days (2013-05-13, analysis of 2013-06-03 15:12:37.355) 18:59:25.211 INFO .bpSensorsExecutor - Initializer ProjectFileSystemLogger... 18:59:25.212 INFO jectFileSystemLogger - Excluded tests: [**/package-info.java] 18:59:25.212 INFO .bpSensorsExecutor - Initializer ProjectFileSystemLogger done: 1 ms 18:59:25.213 INFO p.PhasesTimeProfiler - Sensor JavaSourceImporter... 18:59:25.224 INFO p.PhasesTimeProfiler - Sensor JavaSourceImporter done: 11 ms 

As you can see, the intruder module does not show the line where it finds the source directories.

I turned on gradle debug logs and I saw that these values โ€‹โ€‹are printed:

 RootProj.MyMod.sonar.modules: versioned RootProj.MyMod.sonar.sources: D:\eCommerce\code\R0_3\RootProj\MyMod\src RootProj.MyMod.versioned.catalog.sonar.sources: D:\eCommerce\code\R0_3\RootProj\MyMod\versioned\catalog\src RootProj.MyMod.versioned.sonar.modules: catalog RootProj.MyMod.versioned.sonar.sources: D:\eCommerce\code\R0_3\RootProj\MyMod\versioned\src 

The above lines were not all together. I just inserted the values โ€‹โ€‹that I was interested in.

My assumption was that since RootProj.MyMod.versioned does not have java classes, an error in the gradle plugin or sonar, by itself, causes it to skip classes in the parent directory true.

Therefore I used skipProject = true for RootProj.MyMod.versioned . This fixed the problem and I see that classes are being reported for RootProj.MyMod, but Sonar is no longer trying to run a report for RootProj.MyMod.versioned.catalog, which has files.

So, I'm stuck in losing Sonar reports for 343 classes or 33 classes. I would rather not choose.

So, finally, my question is: Is there a way to disable the launch of reports only for a project using ZERO classes, and not its parent or children?

FYI, if it has any relevance, I install only temporary compilation dependencies using syntax, for example:

 compile group:'ATG_MODULE', name:'mymodule', version:'10.1.1' 

Dependencies are resolved by the user converter.

A custom resolver is supported by me, but since the compilation and the eclipse plugin are working fine, I assume this is not the source of the problem.

EDIT

As Peter Niederwizer mentioned, the Sonar runner only works with sheet projects. But there must be a way to configure the gradle sonar plugin to treat the hierarchy as flat so that all projects are sheet projects. In sonar, you could probably set sonar.modules in the root project to the names of each of the projects you want to parse. But how to do it in Gradle?

I tried setting sonar.modules in each project to null , but this does not seem to have any effect.

+6
source share
1 answer

Sonar Runner (with Gradle integration) is able to analyze only code in sheets. If you want to see support for code analysis in projects other than worksheets, ping sonar people.

+5
source

Source: https://habr.com/ru/post/947116/


All Articles