Maven multi modules, sonar reports and tests coverage : is aggregation needed?

Hi,

I try to configure a multi modules maven project to create sonar reports. I followed this “solution” : sonar multi modules example .

I have an issue and a question.

Question : I noticed that if i did not set up sonar reports aggregation, Sonar displays coverage information on the whole project and not only module by module. So I wonder if reports aggreation is really needed ?

Generating sonar report i have this issue :

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven plugin:3.9.1.2184:sonar (analyze-ocde) on project couverture: Illegal char <
 at index 51: ***\ jacoco-aggregate\jacoco.xml

It seems that the XML is not well formed, how to fix that ?

I use :

  • sonar-maven-plugin 3.9.1.2184
  • jacoco-maven-plugin 0.8.8
  • maven-surefire-plugin 3.0.0-M7
  • spring-boot-starter-test 2.7.1

Hey there.

The use of report-aggregate is as follows:

This also allows to create coverage reports when tests are in separate projects than the code under test, for example in case of integration tests.

This is the case in the example you shared – where tests exist both within each module and in a separate module (which tests functionality using both modules).

It’s not quite clear to me where in the execution you’re facing this error (at a glance, I’m suspicious of the whitespace before jacoco-aggregate). Feel free to share more details about your project configuration (pom.xml files, a wider window of logs)

Hi Colin,

First, a great thanks for your answer about aggregation, in my project I have no test outside a code module, so in fact i do not need aggregation. Maybe this is the cause of my issue …

I have 3 modules with only one that contains unit tests and a module dedicated to report aggregation.

Here is the sonar plugin configuration in parent pom :

					<plugin>
						<groupId>org.sonarsource.scanner.maven</groupId>
						<artifactId>sonar-maven-plugin</artifactId>
						<version>${sonar.version}</version>
						<executions>
							<execution>
								<phase>install</phase>
								<id>analyze-ocde</id>
								<goals>
									<goal>sonar</goal>
								</goals>
							</execution>
						</executions>
					</plugin>

Here is the jacoco pugin configuration in parent pom :

<plugin>
						<groupId>org.jacoco</groupId>
						<artifactId>jacoco-maven-plugin</artifactId>
						<version>${jacoco.version}</version>
						<executions>
							<execution>
								<id>prepare-agent</id>
								<goals>
									<goal>prepare-agent</goal>
								</goals>
							</execution>
							<execution>
								<id>report</id>
								<goals>
									<goal>report</goal>
								</goals>
								<configuration>
									<formats>
										<format>XML</format>
									</formats>
								</configuration>
							</execution>
						</executions>
					</plugin>

And in the module dedicated to aggregation, the sonar plugin is configured as :sl

			<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<version>${jacoco.version}</version>
				<executions>
					<execution>
						<id>report-aggregate</id>
						<phase>verify</phase>
						<goals>
							<goal>report-aggregate</goal>
						</goals>
					</execution>
				</executions>
			</plugin>