Skip to content
Snippets Groups Projects

Ejemplo de pom file (maven)

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by yania
    Edited
    pom.xml 4.72 KiB
    <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>
      <groupId>2017-2018-tds-e4</groupId>
      <artifactId>p3</artifactId>
      <name>2017-2018 práctica 3 TDS equipo 4</name>
      <version>0.0.1-SNAPSHOT</version>
    	<properties>
    		<maven.compiler.source>1.8</maven.compiler.source>
    		<maven.compiler.target>1.8</maven.compiler.target>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    	</properties>
    	<dependencies>
    	    <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.9.5</version>
                <scope>test</scope>
            </dependency>
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.12</version>
    			<scope>test</scope>
    		</dependency>
    		<!-- https://mvnrepository.com/artifact/org.easymock/easymock -->
    		<dependency>
    			<groupId>org.easymock</groupId>
    			<artifactId>easymock</artifactId>
    			<version>3.4</version>
    			<scope>test</scope>
    		</dependency>
    	</dependencies>
    	<profiles>
    		<profile>
    			<id>Unit</id>
    			<properties>
    				<testcase.groups>uva.inf.parasonarqube.Unit</testcase.groups>
    			</properties>
    		</profile>
    		<profile>
    			<id>Isolation</id>
    			<properties>
    				<testcase.groups>uva.inf.parasonarqube.Isolation</testcase.groups>
    			</properties>
    		</profile>
    		<profile>
    			<id>Sequence</id>
    			<properties>
    				<testcase.groups>uva.inf.parasonarqube.Sequence</testcase.groups>
    			</properties>
    		</profile>
    		<profile>
    			<id>Integration</id>
    			<properties>
    				<testcase.groups>uva.inf.parasonarqube.Integration</testcase.groups>
    			</properties>
    		</profile>
    		<profile>
    			<id>TDD</id>
    			<properties>
    				<testcase.groups>uva.inf.parasonarqube.TDD</testcase.groups>
    			</properties>
    		</profile>
      <!-- BEGIN: Specific to mapping unit tests and covered code -->
        <profile>
          <id>coverage-per-test</id>
          
          <build>
            <plugins>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <!-- Minimal supported version is 2.4 -->
                <version>2.20</version>
                <configuration>
                  <properties>
                    <property>
                      <name>listener</name>
                      <value>org.sonar.java.jacoco.JUnitListener</value>
                    </property>
                  </properties>
                </configuration>
              </plugin>
            </plugins>
          </build>
    
          <dependencies>
            <dependency>
              <groupId>org.codehaus.sonar-plugins.java</groupId>
              <artifactId>sonar-jacoco-listeners</artifactId>
              <version>1.2</version>
              <scope>test</scope>
            </dependency>
          </dependencies>
        </profile>
      <!-- END: Specific to mapping unit tests and covered code -->
    	</profiles>
    	<build>
    		<pluginManagement>
    			<plugins>
    				<plugin>
    					<groupId>org.apache.maven.plugins</groupId>
    					<artifactId>maven-surefire-plugin</artifactId>
    					<version>2.20</version>
    					<configuration>
    						<groups>${testcase.groups}</groups>
    					</configuration>
    					<dependencies>
    						<dependency>
    							<groupId>org.apache.maven.surefire</groupId>
    							<artifactId>surefire-junit47</artifactId>
    							<version>2.20</version>
    						</dependency>
    					</dependencies>
    				</plugin>
    				<plugin>
      					<groupId>org.jacoco</groupId>
      					<artifactId>jacoco-maven-plugin</artifactId>
      					<version>0.8.2</version>
    				</plugin>
    				<plugin>
            				<groupId>org.sonarsource.scanner.maven</groupId>
            				<artifactId>sonar-maven-plugin</artifactId>
            				<version>3.5.0.1254</version>
          			</plugin>
    			</plugins>
    		</pluginManagement>
    	</build>
    	<reporting>
        		<plugins>
          			<plugin>
            			<groupId>org.apache.maven.plugins</groupId>
            			<artifactId>maven-project-info-reports-plugin</artifactId>
            			<version>2.7</version>
          		</plugin>
    			<plugin>
                			<groupId>org.apache.maven.plugins</groupId>
                			<artifactId>maven-jxr-plugin</artifactId>
                			<version>2.3</version>
            	</plugin>
    			<plugin>
            			<groupId>org.apache.maven.plugins</groupId>
            			<artifactId>maven-pmd-plugin</artifactId>
            			<version>3.8</version>
            			<configuration>
              				<linkXref>true</linkXref>
              				<sourceEncoding>utf-8</sourceEncoding>
              				<minimumTokens>100</minimumTokens>
              				<targetJdk>1.8</targetJdk>
            			</configuration>
          			</plugin>
        		</plugins>
      	</reporting>
    </project>
    • mvn clean compile test-compile;

      mvn -Djacoco.destFile=target/coverage/jacoco.exec org.jacoco:jacoco-maven-plugin:prepare-agent install -Pcoverage-per-test;

      mvn -X -Djacoco.dataFile=target/coverage/jacoco.exec -Djacoco.outputDirectory=./jacoco_ut org.jacoco:jacoco-maven-plugin:report

      mvn sonar:sonar -Dsonar.host.url=https://sonarqube.inf.uva.es/ -Dsonar.login=hereyourusertoken -Dsonar.analysis.mode=publish -Dsonar.issuesReport.console.enable=true -Dsonar.jacoco.reportPath=target/coverage/jacoco.exec -Dsonar.junit.reportPaths=target/surefire-reports `

      • Con la primera orden maven se eliminan restos de cualquier compilación y ejecución anterior y volvemos a compilar los fuentes del código y los fuentes de tests.
      • Con la segunda, se prepara el agente jacoco (Java Code Coverage) para realizar el análisis de cobertura.
      • A continuación, con la tercera orden maven, se realiza el análisis de cobertura y se almacena en el archivo jacoco.exec como se indica.
      • Para finalizar, se lanza el análisis al servidor sonarqube aportando el informe del resultado de los tests ejecutados y el archivo jacoco.exec con el informe de cobertura. El login se realiza mediante un user token generado para esta acción, y actualmente revocado por cuestiones de seguridad.
      Edited by yania
    • Cuando se lanza el análisis de cobertura se ejecutan los tests (tercera orden del comentario anterior). En esta orden se pueden usar los profiles de tests definidos en el pom file.

      Por ejemplo mvn -P TDD,Unit,Sequence,Integration ...

      Los tests como Isolation realmente duplican otros pero utilizando objetos simulados (mocks) en lugar de los reales.

      Edited by yania
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment