Skip to content

Commit 36f4acd

Browse files
committed
issue-1533: Setting up generic jacoco and sonar coverage configuration for multi-module projects.
This is intentionally using a `merge` in a `post-integration-test` since `report-aggregator` does not generate proper reports.
1 parent a09e9be commit 36f4acd

File tree

1 file changed

+97
-98
lines changed

1 file changed

+97
-98
lines changed

pom.xml

Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
<strongbox.host>localhost</strongbox.host>
5454
<strongbox.port>48080</strongbox.port>
5555

56+
<!-- Sonar: -->
57+
<sonar.language>java</sonar.language>
58+
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
59+
<sonar.coverage.jacoco.xmlReportPaths>target/jacoco-merged/jacoco-merged-report/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
60+
<sonar.exclusions>**/*Test.java,**/*TestIT.java,**/*Exception.java,**/InMemoryOrientDbConfig.java</sonar.exclusions>
61+
<!-- Sonar. -->
62+
5663
<!-- Version properties: -->
5764
<version.maven.indexer>6.0.1-SNAPSHOT</version.maven.indexer>
5865

@@ -98,7 +105,8 @@
98105
<version.awaitility>4.0.1</version.awaitility>
99106
<version.asm>6.0</version.asm>
100107
<version.jtwig>5.87.0.RELEASE</version.jtwig>
101-
<version.jacoco>0.8.2</version.jacoco>
108+
<version.jacoco>0.8.4</version.jacoco>
109+
<version.sonar-maven-plugin>3.7.0.1746</version.sonar-maven-plugin>
102110
<version.codacy.mvn.plugin>1.1.0</version.codacy.mvn.plugin>
103111
<version.semver>0.9.34-SNAPSHOT</version.semver>
104112
<version.springfox>2.9.2</version.springfox>
@@ -162,17 +170,15 @@
162170
<inherited>true</inherited>
163171
<configuration>
164172
<useSystemClassLoader>false</useSystemClassLoader>
165-
<argLine>-Xmx1024m -Xms512m ${surefireArgLine}</argLine>
173+
<!-- Use @{} (late property evaluation) instead of ${} or jacoco will not write the exec file! -->
174+
<argLine>@{surefireArgLine} -Xmx1024m -Xms512m</argLine>
166175
<includes>
167176
<include>**/*Test</include>
168177
</includes>
169178
<excludes>
170179
<exclude>**/*TestIT</exclude>
171180
</excludes>
172181

173-
<!-- This field needs to be set to 1 or jacoco reports will be incorrect/missing! -->
174-
<forkCount>1</forkCount>
175-
176182
<systemPropertyVariables>
177183
<strongbox.home>${project.build.directory}/strongbox</strongbox.home>
178184
<strongbox.vault>${project.build.directory}/strongbox-vault</strongbox.vault>
@@ -187,13 +193,6 @@
187193
<strongbox.nuget.download.feed>false</strongbox.nuget.download.feed>
188194
<strongbox.download.indexes>false</strongbox.download.indexes>
189195
</systemPropertyVariables>
190-
191-
<properties>
192-
<property>
193-
<name>listener</name>
194-
<value>org.sonar.java.jacoco.JUnitListener</value>
195-
</property>
196-
</properties>
197196
</configuration>
198197
</plugin>
199198
<plugin>
@@ -203,7 +202,8 @@
203202

204203
<configuration>
205204
<useSystemClassLoader>false</useSystemClassLoader>
206-
<argLine>${failsafeArgLine}</argLine>
205+
<!-- Use @{} (late property evaluation) instead of ${} or jacoco will not write the exec file! -->
206+
<argLine>@{failsafeArgLine}</argLine>
207207
<systemPropertyVariables>
208208
<strongbox.home>${project.build.directory}/strongbox</strongbox.home>
209209
<strongbox.vault>${project.build.directory}/strongbox-vault</strongbox.vault>
@@ -239,7 +239,7 @@
239239
<artifactId>strongbox-common-resources</artifactId>
240240
<version>${project.version}</version>
241241
<type>jar</type>
242-
242+
243243
<overWrite>true</overWrite>
244244
<outputDirectory>${strongbox.home}/etc</outputDirectory>
245245
<includes>logback*xml</includes>
@@ -249,7 +249,7 @@
249249
<artifactId>strongbox-storage-api-resources</artifactId>
250250
<version>${project.version}</version>
251251
<type>jar</type>
252-
252+
253253
<overWrite>true</overWrite>
254254
<outputDirectory>${strongbox.home}</outputDirectory>
255255
<includes>etc/conf/strongbox.yaml</includes>
@@ -259,7 +259,7 @@
259259
<artifactId>strongbox-common-resources</artifactId>
260260
<version>${project.version}</version>
261261
<type>jar</type>
262-
262+
263263
<overWrite>true</overWrite>
264264
<outputDirectory>${strongbox.home}</outputDirectory>
265265
<includes>etc/**</includes>
@@ -285,7 +285,7 @@
285285
<goals>deploy -DaltDeploymentRepository=${serverId}::default::${deployUrl}</goals>
286286
</configuration>
287287
</plugin>
288-
288+
289289
<plugin>
290290
<groupId>org.codehaus.mojo</groupId>
291291
<artifactId>build-helper-maven-plugin</artifactId>
@@ -1389,6 +1389,11 @@
13891389
<build>
13901390
<pluginManagement>
13911391
<plugins>
1392+
<plugin>
1393+
<groupId>org.sonarsource.scanner.maven</groupId>
1394+
<artifactId>sonar-maven-plugin</artifactId>
1395+
<version>${version.sonar-maven-plugin}</version>
1396+
</plugin>
13921397
<plugin>
13931398
<groupId>org.jacoco</groupId>
13941399
<artifactId>jacoco-maven-plugin</artifactId>
@@ -1400,130 +1405,124 @@
14001405
<plugin>
14011406
<groupId>org.jacoco</groupId>
14021407
<artifactId>jacoco-maven-plugin</artifactId>
1408+
<version>${version.jacoco}</version>
1409+
<inherited>true</inherited>
14031410
<configuration>
14041411
<append>true</append>
1412+
<includes>
1413+
<include>org/carlspring/**</include>
1414+
</includes>
1415+
<excludes>
1416+
<exclude>org/carlspring/strongbox/app/*</exclude>
1417+
<exclude>org/carlspring/strongbox/config/*</exclude>
1418+
<exclude>org/carlspring/strongbox/data/server/InMemoryOrientDbServer.class</exclude>
1419+
<exclude>com/orientechnologies/*</exclude>
1420+
<exclude>org/orientechnologies/*</exclude>
1421+
<exclude>org/springframework/*</exclude>
1422+
<exclude>com/hazelcast/*</exclude>
1423+
<exclude>*Test.java</exclude>
1424+
<exclude>*TestIT.java</exclude>
1425+
<exclude>*Exception.java</exclude>
1426+
</excludes>
14051427
</configuration>
14061428
<executions>
1407-
<!--
1408-
Prepares the property pointing to the JaCoCo runtime agent which
1409-
is passed as VM argument when Maven the Surefire plugin is executed.
1410-
-->
14111429
<execution>
1412-
<id>pre-unit-test</id>
1430+
<id>prepare-unit-test-agent</id>
14131431
<goals>
14141432
<goal>prepare-agent</goal>
14151433
</goals>
14161434
<configuration>
1417-
<!-- Sets the path to the file which contains the execution data. -->
1418-
<destFile>${project.build.directory}/jacoco-ut.exec</destFile>
1419-
<!--
1420-
Sets the name of the property containing the settings
1421-
for JaCoCo runtime agent.
1422-
-->
1435+
<destFile>${project.build.directory}/jacoco/jacoco-ut.exec</destFile>
14231436
<propertyName>surefireArgLine</propertyName>
14241437
</configuration>
14251438
</execution>
1426-
1427-
1428-
<!--
1429-
Prepares the property pointing to the JaCoCo runtime agent which
1430-
is passed as VM argument when Maven the Failsafe plugin is executed.
1431-
-->
14321439
<execution>
1433-
<id>pre-integration-test</id>
1434-
<phase>pre-integration-test</phase>
1440+
<id>prepare-integration-test-agent</id>
14351441
<goals>
1436-
<goal>prepare-agent</goal>
1442+
<goal>prepare-agent-integration</goal>
14371443
</goals>
1444+
<phase>pre-integration-test</phase>
14381445
<configuration>
1439-
<!-- Sets the path to the file which contains the execution data. -->
1440-
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
1441-
<!--
1442-
Sets the name of the property containing the settings
1443-
for JaCoCo runtime agent.
1444-
-->
1446+
<destFile>${project.build.directory}/jacoco/jacoco-it.exec</destFile>
14451447
<propertyName>failsafeArgLine</propertyName>
14461448
</configuration>
14471449
</execution>
1448-
1449-
<!-- Merge jacoco-it and jacoco-ut into jacoco-aggregated (necessary for next step) -->
14501450
<execution>
1451-
<id>merge-results</id>
1452-
<phase>verify</phase>
1451+
<id>report-unit-tests</id>
1452+
<goals>
1453+
<goal>report</goal>
1454+
</goals>
1455+
<configuration>
1456+
<dataFile>${project.build.directory}/jacoco/jacoco-ut.exec</dataFile>
1457+
<outputDirectory>${project.build.directory}/jacoco/jacoco-ut</outputDirectory>
1458+
</configuration>
1459+
</execution>
1460+
<execution>
1461+
<id>report-integration-tests</id>
1462+
<goals>
1463+
<goal>report-integration</goal>
1464+
</goals>
1465+
<configuration>
1466+
<dataFile>${project.build.directory}/jacoco/jacoco-it.exec</dataFile>
1467+
<outputDirectory>${project.build.directory}/jacoco/jacoco-it</outputDirectory>
1468+
</configuration>
1469+
</execution>
1470+
<execution>
1471+
<id>merge-unit-and-integration</id>
1472+
<phase>post-integration-test</phase>
14531473
<goals>
14541474
<goal>merge</goal>
14551475
</goals>
14561476
<configuration>
14571477
<fileSets>
14581478
<fileSet>
1459-
<directory>${project.build.directory}</directory>
1479+
<directory>${project.build.directory}/jacoco/</directory>
14601480
<includes>
1461-
<include>jacoco-it.exec</include>
1462-
<include>jacoco-ut.exec</include>
1481+
<include>jacoco-*.exec</include>
14631482
</includes>
14641483
</fileSet>
14651484
</fileSets>
1466-
<destFile>${project.build.directory}/jacoco-aggregated.exec</destFile>
1485+
<destFile>${project.build.directory}/jacoco-merged/jacoco.exec</destFile>
14671486
</configuration>
14681487
</execution>
1469-
1470-
<!-- We need this step for submitting reports to codacy -->
14711488
<execution>
1472-
<id>report-coverage</id>
1473-
<phase>verify</phase>
1489+
<id>create-merged-report</id>
1490+
<phase>post-integration-test</phase>
14741491
<goals>
14751492
<goal>report</goal>
14761493
</goals>
14771494
<configuration>
1478-
<!-- Sets the path to the file which contains the execution data. -->
1479-
<dataFile>${project.build.directory}/jacoco-aggregated.exec</dataFile>
1480-
<!-- Sets the output directory for the code coverage report. -->
1481-
<outputDirectory>${project.reporting.outputDirectory}/jacoco-aggregated-report</outputDirectory>
1495+
<dataFile>${project.build.directory}/jacoco-merged/jacoco.exec</dataFile>
1496+
<outputDirectory>${project.build.directory}/jacoco-merged/jacoco-merged-report</outputDirectory>
14821497
</configuration>
14831498
</execution>
1484-
1485-
</executions>
1486-
</plugin>
1487-
</plugins>
1488-
</build>
1489-
</profile>
1490-
1491-
<profile>
1492-
<id>codacy</id>
1493-
<activation>
1494-
<activeByDefault>false</activeByDefault>
1495-
</activation>
1496-
<build>
1497-
<pluginManagement>
1498-
<plugins>
1499-
<plugin>
1500-
<groupId>com.gavinmogan</groupId>
1501-
<artifactId>codacy-maven-plugin</artifactId>
1502-
<version>${version.codacy.mvn.plugin}</version>
1503-
</plugin>
1504-
</plugins>
1505-
</pluginManagement>
1506-
<plugins>
1507-
<!-- codacy -->
1508-
<plugin>
1509-
<groupId>com.gavinmogan</groupId>
1510-
<artifactId>codacy-maven-plugin</artifactId>
1511-
<configuration>
1512-
<!-- expects to receive the jacoco.xml aggregated report which comes from the report-coverage execution -->
1513-
<coverageReportFile>${project.reporting.outputDirectory}/jacoco-aggregated-report/jacoco.xml</coverageReportFile>
1514-
<apiToken>${env.CODACY_API_TOKEN}</apiToken>
1515-
<projectToken>${env.CODACY_PROJECT_TOKEN_STRONGBOX}</projectToken>
1516-
<commit>${env.GIT_COMMIT}</commit>
1517-
<codacyApiBaseUrl>https://api.codacy.com</codacyApiBaseUrl>
1518-
<failOnMissingReportFile>false</failOnMissingReportFile>
1519-
</configuration>
1520-
<executions>
15211499
<execution>
1522-
<id>post-test</id>
1500+
<id>check</id>
15231501
<phase>verify</phase>
15241502
<goals>
1525-
<goal>coverage</goal>
1503+
<goal>check</goal>
15261504
</goals>
1505+
<configuration>
1506+
<!-- TODO: We need to set this to true when the coverage increases enough -->
1507+
<haltOnFailure>false</haltOnFailure>
1508+
<rules>
1509+
<rule>
1510+
<element>BUNDLE</element>
1511+
<excludes>
1512+
<exclude>*Test.java</exclude>
1513+
<exclude>*TestIT.java</exclude>
1514+
</excludes>
1515+
<limits>
1516+
<limit>
1517+
<counter>INSTRUCTION</counter>
1518+
<value>COVEREDRATIO</value>
1519+
<minimum>0.7</minimum>
1520+
</limit>
1521+
</limits>
1522+
</rule>
1523+
</rules>
1524+
<dataFile>${project.build.directory}/jacoco-merged/jacoco.exec</dataFile>
1525+
</configuration>
15271526
</execution>
15281527
</executions>
15291528
</plugin>

0 commit comments

Comments
 (0)