All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jacoco.maven.AgentMojo Maven / Gradle / Ivy

Go to download

The JaCoCo Maven Plugin provides the JaCoCo runtime agent to your tests and allows basic report creation.

There is a newer version: 0.8.12
Show newest version
/*******************************************************************************
 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Evgeny Mandrikov - initial API and implementation
 *
 *******************************************************************************/
package org.jacoco.maven;

import java.io.File;

import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
 * 

* Prepares a property pointing to the JaCoCo runtime agent that can be passed * as a VM argument to the application under test. Depending on the project * packaging type by default a property with the following name is set: *

* *
    *
  • tycho.testArgLine for packaging type eclipse-test-plugin and
  • *
  • argLine otherwise.
  • *
* *

* If your project already defines VM arguments for test execution, be sure that * they will include property defined by JaCoCo. *

* *

* One of the ways to do this in case of maven-surefire-plugin - is to use * syntax for late property evaluation: *

* *
 *   <plugin>
 *     <groupId>org.apache.maven.plugins</groupId>
 *     <artifactId>maven-surefire-plugin</artifactId>
 *     <configuration>
 *       <argLine>@{argLine} -your -extra -arguments</argLine>
 *     </configuration>
 *   </plugin>
 * 
* *

* You can define empty property to avoid JVM startup error Could not find or load main class @{argLine} * when using late property evaluation and jacoco-maven-plugin not executed. *

* *

* Another way is to define "argLine" as a Maven property rather than * as part of the configuration of maven-surefire-plugin: *

* *
 *   <properties>
 *     <argLine>-your -extra -arguments</argLine>
 *   </properties>
 *   ...
 *   <plugin>
 *     <groupId>org.apache.maven.plugins</groupId>
 *     <artifactId>maven-surefire-plugin</artifactId>
 *     <configuration>
 *       <!-- no argLine here -->
 *     </configuration>
 *   </plugin>
 * 
* *

* Resulting coverage information is collected during execution and by default * written to a file when the process terminates. *

* * @since 0.5.3 */ @Mojo(name = "prepare-agent", defaultPhase = LifecyclePhase.INITIALIZE, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true) public class AgentMojo extends AbstractAgentMojo { /** * Path to the output file for execution data. */ @Parameter(property = "jacoco.destFile", defaultValue = "${project.build.directory}/jacoco.exec") private File destFile; /** * @return the destFile */ @Override File getDestFile() { return destFile; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy