#aem #jacoco #maven-surefire-plugin #jacoco-maven-plugin #aem-6
#aem #jacoco #maven-верный плагин #jacoco-maven-plugin #aem-6
Вопрос:
- Я пытаюсь настроить проверку JaCoCo в моем многомодульном проекте AEM 6.4.
- Я написал тестовые классы для расширений JUnit5, которые хорошо компилируются.
- Я вижу, что отчет также публикуется на моем сервере Sonar, охват составляет 45,9% — сбой.
- Когда я развертываю проект Maven с помощью maven Run Configuration: mvn clean verify, он всегда показывает, что все модули успешно развернуты.
Объявление корневых переменных POM:
<properties>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.language>java</sonar.language>
<!-- JaCoCo -->
<jacoco.percentage.instruction>0.98</jacoco.percentage.instruction>
</properties>
Настройка надежного, отказоустойчивого Maven с корневым POM и плагинов JaCoCo
<build>
<plugins>
<!-- Maven Surefire Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<argLine>${jacocoArgLine} -Xmx256m</argLine>
</configuration>
</plugin>
<!-- Maven Failsafe Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<!-- JaCoCo Plugin for Code Coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<destFile>${sonar.jacoco.reportPaths}</destFile
<dataFile>${sonar.jacoco.reportPaths}</dataFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacocoArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<dataFile>${sonar.jacoco.reportPaths}</dataFile>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>PACKAGE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Пожалуйста, обратите внимание, что я не настраивал какой-либо плагин в POM-файлах core или it.tests module.
Вывод из журналов — Core Bundle:
[INFO] Building Test - Core 0.0.1-SNAPSHOT [2/5]
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ test.core ---
[INFO] Deleting C:AppsWorkspacegittest-bitbucketcoretarget
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ test.core ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.3:prepare-agent (prepare-agent) @ test.core ---
[INFO] jacocoArgLine set to -javaagent:C:\Users\Public\.m2\repository\org\jacoco\org.jacoco.agent\0.8.3\org.jacoco.agent-0.8.3-runtime.jar=destfile=C:\Apps\Workspace\git\test-bitbucket\core\..\target\jacoco.exec,append=true
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ test.core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:AppsWorkspacegittest-bitbucketcoresrcmainresources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ test.core ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 20 source files to C:AppsWorkspacegittest-bitbucketcoretargetclasses
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ test.core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:AppsWorkspacegittest-bitbucketcoresrctestresources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ test.core ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ test.core ---
[INFO] No tests to run.
[INFO]
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.3:check (check) @ marketing-garage.core ---
[INFO] Skipping JaCoCo execution due to missing execution data file:C:AppsWorkspacegittest-bitbucketcore..targetjacoco.exec
Вывод из журналов — Пакет тестов:
[INFO] Building Test - Integration 0.0.1-SNAPSHOT [5/5]
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ test.it.tests ---
[INFO] Deleting C:AppsWorkspacegittest-bitbucketit.teststarget
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) @ test.it.tests ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.3:prepare-agent (prepare-agent) @ test.it.tests ---
[INFO] jacocoArgLine set to -javaagent:C:\Users\Public\.m2\repository\org\jacoco\org.jacoco.agent\0.8.3\org.jacoco.agent-0.8.3-runtime.jar=destfile=C:\Apps\Workspace\git\test-bitbucket\it.tests\..\target\jacoco.exec,append=true
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ test.it.tests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:AppsWorkspacegittest-bitbucketit.testssrcmainresources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ test.it.tests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ test.it.tests ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ test.it.tests ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to C:AppsWorkspacegittest-bitbucketit.teststargettest-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ test.it.tests ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.test.it.tests.LogoutServletTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.603 s - in com.test.it.tests.LogoutServletTest
[INFO] Running com.test.it.tests.SocialFeedsServiceTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.731 s - in com.test.it.tests.SocialFeedsServiceTest
[INFO]
[INFO] Results:
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-bundle-plugin:4.1.0:bundle (default-bundle) @ test.it.tests -
[WARNING] Bundle com.test:test.it.tests:bundle:0.0.1-SNAPSHOT : The JAR is empty: The instructions for the JAR named com.test.it.tests did not cause any content to be included, this is likely wrong
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.3:check (check) @ test.it.tests ---
[INFO] Loading execution data file C:AppsWorkspacegittest-bitbucketit.tests..targetjacoco.exec
[INFO] Analyzed bundle 'test.it.tests' with 0 classes
[INFO] All coverage checks have been met.
[INFO] -----------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] test 0.0.1-SNAPSHOT ................ SUCCESS [ 2.091 s]
[INFO] Test - Core ........................ SUCCESS [ 15.467 s]
[INFO] Test - UI apps ..................... SUCCESS [ 55.583 s]
[INFO] Test - UI content .................. SUCCESS [ 47.815 s]
[INFO] Test - Integration 0.0.1-SNAPSHOT SUCCESS [ 36.362 s]
[INFO] -----------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------------
[INFO] Total time: 02:41 min
[INFO] Finished at: 2019-03-25T11:08:31 05:30
[INFO] -----------------------------------------------------------------------
Я ожидал, что сборка завершится неудачей, если охват будет ниже 80%, но эта конфигурация передает все сборки с точки зрения сборки Maven.
Комментарии:
1. Вы нашли решение?
2. Возникла точно такая же проблема. Он отлично работал с верной версией 2.12.x, но не работал с 2.22.0 . Для меня я не настраивал никакой проверки покрытия, которая по-прежнему демонстрирует то же поведение. Я думаю, что некоторые инструменты не сработали. @Som вы получили какой-либо ответ