0

I am trying to generate a jacoco report for my multi module project. However I need to run mvn verify twice in order to get the correct coverage. After the first mvn verify I get a report, but with 0% coverage. Here is my parent pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>at.ac.tuwien.inso.peso</groupId>
  <artifactId>swme</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>

  <url>http://maven.apache.org</url>
  <modules>
    <module>backend</module>
    <module>frontend</module>
  </modules>

  <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <vaadin.version>23.0.9</vaadin.version>
    <db.user>postgres</db.user>
    <db.pw>postgres</db.pw>
    <db.driver>org.postgresql.Driver</db.driver>
    <db.url>jdbc:postgresql://localhost:5432/swme</db.url>
    <project.version>0.0.1-SNAPSHOT</project.version>
    <jacoco.version>0.8.8</jacoco.version>
  </properties>


</project>

and here my frontend pom file where the integration tests are executed

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>swme</artifactId>
        <groupId>at.ac.tuwien.inso.peso</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>frontend</artifactId>
    <packaging>war</packaging>
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <repositories>
        <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

        <!-- Main Maven repository -->
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <!-- Repository used by many Vaadin add-ons: https://vaadin.com/directory -->
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <type>pom</type>
                <scope>import</scope>
                <version>${vaadin.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>



   <dependencies>
       <!-- TESTING -->
       <dependency>
           <groupId>com.vaadin</groupId>
           <artifactId>vaadin-testbench</artifactId>
           <version>23.0.9</version>
           <scope>test</scope>
       </dependency>
       <dependency>
           <groupId>io.github.bonigarcia</groupId>
           <artifactId>webdrivermanager</artifactId>
           <version>5.1.1</version>
           <scope>test</scope>
       </dependency>
       <dependency>
           <groupId>at.ac.tuwien.inso.peso</groupId>
           <artifactId>backend</artifactId>
           <version>${project.version}</version>
           <scope>compile</scope>
       </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <!-- Replace artifactId with vaadin-core to use only free components -->
        <artifactId>vaadin-core</artifactId>
        <exclusions>
            <!-- Fusion is only supported in Spring Boot currently, exclude obsolete dependencies -->
            <exclusion>
                <groupId>com.vaadin</groupId>
                <artifactId>fusion-endpoint</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
       <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>4.0.1</version>
           <scope>provided</scope>
       </dependency>
    <!-- Added to provide logging output as Flow uses -->
    <!-- the unbound SLF4J no-operation (NOP) logger implementation -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
    </dependency>
</dependencies>
<build>
    <defaultGoal>jetty:run</defaultGoal>
    <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.8.1</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>
                    <argLine>${failsafe.jacoco.args}</argLine>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>before-integration-test-execution</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</destFile>
                            <propertyName>failsafe.jacoco.args</propertyName>
                        </configuration>
                    </execution>

                    <execution>
                        <id>after-integration-test-execution</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.build.directory}/jacoco-output/jacoco-integration-tests.exec</dataFile>
                            <outputDirectory>${project.reporting.outputDirectory}/jacoco-integration-test-coverage-report</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <webResources>
                    <resource>
                        <!--suppress UnresolvedMavenProperty -->
                        <directory>${maven.multiModuleProjectDirectory}/frontend/src/main/webapp</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>


        <!-- We use jetty plugin, replace it with your favourite developing servlet container -->

        <plugin>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-maven-plugin</artifactId>
            <version>${vaadin.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-frontend</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.4.36.v20210114</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <stopPort>8005</stopPort>
                <stopKey>STOP</stopKey>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                        <goal>run-forked</goal>
                    </goals>
                    <configuration>
                        <useTestClasspath>true</useTestClasspath>
                        <useTestScope>true</useTestScope>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                        <daemon>true</daemon>
                        <jvmArgs>${failsafe.jacoco.args}</jvmArgs>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                    <configuration>
                        <stopWait>5</stopWait>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <finalName>swme</finalName>
</build>
    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <version>${vaadin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

I dont get it why the report is correct the second time I call mvn verify. My backend module has no tests, thats why I did not post it here. After the second mvn verify I get the correct result. The tutorials I followed: https://natritmeyer.com/howto/reporting-aggregated-unit-and-integration-test-coverage-with-jacoco/ and https://github.com/daniellundmark/jetty-jacoco-example/blob/master/pom.xml

What am I missing?

  • Try to bind the report to another phase. Maybe post-integration-test is too early – Simon Martinelli May 25 '22 at 05:17
  • When I bind the report to verify, which is the next state, the report gets not created at all – lokinamo May 25 '22 at 06:20
  • Since this is tagged [vaadin], is this problem due to the vaadin-maven-plugin? Does selectively removing "vaadin things" from the config make things better? If so it might help to state that in the question -- or remove the tag and state, that it's irrelevant. – cfrick May 25 '22 at 07:00
  • It is tagged with vaadin because it is a vaadin setup and I hoped I would find people who use vaadin and jacoco together. Removing vaadin things would just mean removing the main program – lokinamo May 25 '22 at 14:06

0 Answers0