Search code examples
mavenmaven-3pom.xmlmaven-site-pluginjacoco-maven-plugin

Maven site not link to Jacoco report


I can generate Jacoco report from profile 'test' and is save inside site folder. But when I execute profile 'documentacion' which contains site generation description, I get all reports link in site, except link to Jacoco report, but this report still appears inside site folder.

This is part of my POM (I cut down part which is not important):

<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">
    <dependencies>
        <!-- Tests -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!-- Dependencia para el informe de traducción -->
        <dependency>
            <groupId>com.googlecode.l10n-maven-plugin</groupId>
            <artifactId>l10n-maven-plugin</artifactId>
            <version>1.8</version>
        </dependency>
        ....
    </dependencies>
    <!-- Configuración común a todas las fases -->
    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.fxml</include>
                </includes>                
                <excludes>
                    <exclude>package-info.java</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.css</include>
                    <include>**/*.png</include>
                    <include>**/*.fxml</include>
                    <include>**/*.ttf</include>
                    <include>*.properties</include>
                    <include>version.prop</include>
                </includes>
            </resource>
        </resources>
    </build>
    <!-- Perfiles -->
    <profiles>
        ......
        <profile>
            <id>documentacion</id>            
            <activation>
                <jdk>[1.8,)</jdk>
            </activation>
            <build>
                <defaultGoal>site:site</defaultGoal>
                <plugins>
                    <!-- Site -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-site-plugin</artifactId>
                        <version>3.4</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.2.201409121644</version>
                    </plugin>   
                </plugins>
            </build>            
            <reporting>
                <excludeDefaults>true</excludeDefaults>
                <outputDirectory>${project.build.directory}/site</outputDirectory>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>2.8</version>
                        <configuration>
                            <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                        </configuration>
                        <reportSets>
                            <reportSet>
                                <reports>
                                    <report>summary</report>
                                    <report>index</report>
                                    <report>dependencies</report>
                                    <report>project-team</report>
                                    <report>license</report>
                                    <report>scm</report>
                                    <report>cim</report>
                                    <report>mailing-list</report>
                                    <report>issue-tracking</report>
                                </reports>  
                            </reportSet>
                        </reportSets>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>3.3</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>2.13</version>
                        <configuration>
                            <configLocation>config/sun_checks.xml</configLocation>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jxr-plugin</artifactId>
                        <version>2.5</version>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>findbugs-maven-plugin</artifactId>
                        <version>3.0.0</version>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>l10n-maven-plugin</artifactId>
                        <version>1.0-alpha-2</version>
                        <configuration>
                            <locales>
                                <locale>es</locale>
                            </locales>
                        </configuration>
                    </plugin>        
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-changes-plugin</artifactId>
                        <version>2.11</version>
                        <reportSets>
                            <reportSet>
                                <reports>
                                    <report>changes-report</report>
                                </reports>
                            </reportSet>
                        </reportSets>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.10.1</version>
                        <configuration>
                            <useStandardDocletOptions>false</useStandardDocletOptions>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-report-plugin</artifactId>
                        <version>2.18.1</version>
                    </plugin>
                </plugins>
            </reporting>
        </profile>
        <profile>
            <id>test</id>            
            <activation>
                <jdk>[1.8,)</jdk>
            </activation>
            <build>
                <defaultGoal>validate test</defaultGoal>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <testFailureIgnore>true</testFailureIgnore>                            
                            <additionalClasspathElements>
                                <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
                            </additionalClasspathElements>
                            <argLine>-Dfile.encoding=UTF-8</argLine>
                            <skipTests>${skip.unit.tests}</skipTests>
                        </configuration> 
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.2.201409121644</version>
                        <executions>
                            <execution>
                                <id>pre-unit-test</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/coverage-reports/jacoco.exec</destFile>
                                    <propertyName>surefireArgLine</propertyName>
                                </configuration>
                            </execution>
                            <execution>
                                <id>post-unit-test</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <dataFile>${project.build.directory}/coverage-reports/jacoco.exec</dataFile>
                                    <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>    
        </profile>
    </profiles>   
</project>

So, How can I get site link to Jacoco report?


Solution

  • Finally, I can fix my POM so I get links to Jacoco and Surefire reports from maven site.

    <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">
        <modelVersion>4.0.0</modelVersion>
        ...
        <dependencies>
            <!-- Tests -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            ...
        </dependencies>
        <profiles>
            <profile>
                <id>desarrollo</id>
                <activation>
                    <jdk>[1.8,)</jdk>
                </activation>
                <build>
                    <defaultGoal>clean package</defaultGoal>
                    <plugins>    
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-jar-plugin</artifactId>
                            <version>2.5</version>
                            <configuration>
                                <archive>
                                    <manifest>
                                        <addClasspath>true</addClasspath>
                                        <mainClass>com.***.App</mainClass>
                                    </manifest>
                                </archive>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>documentacion</id>            
                <activation>
                    <jdk>[1.8,)</jdk>
                </activation>
                <build>
                    <defaultGoal>site:site</defaultGoal>
                    <plugins>
                        <!-- Site -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-site-plugin</artifactId>
                            <version>3.4</version>
                        </plugin>
                        <plugin>
                            <groupId>org.jacoco</groupId>
                            <artifactId>jacoco-maven-plugin</artifactId>
                            <version>0.7.2.201409121644</version>
                        </plugin>   
                    </plugins>
                </build>            
                <reporting>
                    <excludeDefaults>true</excludeDefaults>
                    <outputDirectory>${project.build.directory}/site</outputDirectory>
                    <plugins>
                        <!-- Plugin para generar el site con los reports -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.8</version>
                            <configuration>
                                <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
                            </configuration>
                            <reportSets>
                                <reportSet>
                                    <reports>
                                        <report>summary</report>
                                        <report>index</report>
                                        <report>dependencies</report>
                                        <report>project-team</report>
                                        <report>license</report>
                                        <report>scm</report>
                                        <report>cim</report>
                                        <report>mailing-list</report>
                                        <report>issue-tracking</report>
                                    </reports>  
                                </reportSet>
                            </reportSets>
                        </plugin> 
                        <!-- Reporte tests -->
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-report-plugin</artifactId>   
                            <version>2.18.1</version>   
                        </plugin>  
                        <plugin>
                            <groupId>org.jacoco</groupId>
                            <artifactId>jacoco-maven-plugin</artifactId>
                            <version>0.7.2.201409121644</version>
                        </plugin>   
                    <!-- More report plugins place here (PMD, checkstyle...) -->                    
                    </plugins>
                </reporting>
            </profile>
            <profile>
                <id>test</id>            
                <activation>
                    <jdk>[1.8,)</jdk>
                </activation>
                <build>
                    <defaultGoal>validate test</defaultGoal>
                    <plugins>                    
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>2.18.1</version>
                            <configuration>
                                <outputDirectory>${project.build.directory}/site</outputDirectory>
                                <reportsDirectories>
                                    <reportsDirectories>${project.build.directory}/site/surefire-reports</reportsDirectories>
                                </reportsDirectories>
                                <testFailureIgnore>true</testFailureIgnore>                            
                                <additionalClasspathElements>
                                    <additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
                                </additionalClasspathElements>
                                <argLine>${argLine} -Dfile.encoding=UTF-8</argLine>
                            </configuration>        
                            <executions>
                                <execution>
                                    <id>default-test</id>
                                    <phase>test</phase>
                                    <goals>
                                        <goal>test</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>  
                        <!-- Test report -->
                        <plugin>
                            <groupId>org.jacoco</groupId>
                            <artifactId>jacoco-maven-plugin</artifactId>
                            <version>0.7.2.201409121644</version>
                            <executions>
                                <execution>
                                    <id>default-prepare-agent</id>
                                    <goals>
                                        <goal>prepare-agent</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>default-report</id>
                                    <phase>prepare-package</phase>
                                    <goals>
                                        <goal>report</goal>
                                    </goals>
                                </execution>
                                <execution>
                                    <id>default-check</id>
                                    <goals>
                                        <goal>check</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>    
            </profile>
        </profiles>   
    </project>