Why maven-surefire-plugin would run on my integration test - maven

It is weird that I see surefire plugin run on my integration test. Anyone know why ?
[INFO] --- maven-surefire-plugin:2.17:test (default-test) # xxxx ---
[INFO] Surefire report directory: /Users/jzhang/github/project/module-A/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running package.XXXXIT

Yes. It's natural. You need to tell maven-surefire-plugin to skip execution of your tests ending with *IT.java.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

Related

Why no jacoco.exec produced when a single test is run - but it is produced when all tests are run?

I'm running surefire tests with a jacoco agent. When I run mvn verify a jacoco.exec file is produced.
When I run mvn clean verify -Dtest=com.org.MyTest -DfailIfNoTests=false then no jacoco.exec file is produced.
Here is my surefire config.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>test</phase>
<id>testconfig</id>
<configuration>
<argLine>${test.jvm.options} ${jacoco.agent.argLine}</argLine>
<skip>false</skip>
</configuration>
<goals><goal>test</goal></goals>
</execution>
</executions>
</plugin>
Here is my jacoco config
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
<executions>
<execution>
<id>unit_agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>
My question is: Why no jacoco.exec produced when a single test is run - but it is produced when all tests are run?
Log of execution of mvn clean verify -Dtest=com.org.MyTest -DfailIfNoTests=false shows something like (I'm using Apache Maven 3.3.9):
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) # example ---
[INFO] Surefire report directory: /private/tmp/jacoco-example/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.org.MyTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec - in com.org.MyTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (testconfig) # example ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
Notice that maven-surefire-plugin executed two times - one time with id default-test and another execution with id testconfig is actually skipped, while only configuration with id testconfig uses ${jacoco.agent.argLine}.
Change of definition for maven-surefire-plugin on
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
solves the issue.

Why won't maven-antrun-plugin run?

I'm having trouble getting the antrun plugin to run.
I have this configuration in my pom:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>compile</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<echo message="Hello, maven"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run mvn:compile it runs but all I see in the logs about the antrun plugin is this:
[INFO] --- maven-antrun-plugin:1.4:run (default) # datasite-cms ---
project.artifactId
[INFO] Executing tasks
[INFO] Executed tasks
Why isn't the plugin actually doing anything?
Please use an uptodate version of the maven-antrun-plugin if you really need to use maven-antrun-plugin.
The older versions have using the configuration tag: tasks instead of target. But stop using such ancient versions of Maven plugins.

Maven: Does it work for not Java code?

I'm newbie to maven (just 2 days playing with it).
I've some problems setting up maven with jacoco plugin and surefire/failsafe.
Despite it reads and copies the source files it doesn't compile them!
I set new directories as I don't follow the standard maven directory layout but it seems not working. The problem is that I cannot change my project's layout as it's the company's.
So, Im trying to solved it manually.
pom.xml:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.sonar</groupId>
<artifactId>example-java-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Code Coverage - Maven and JaCoCo running tests</name>
<properties>
<!-- Tell SonarQube to execute unit tests during analysis-->
<sonar.dynamicAnalysis>true</sonar.dynamicAnalysis>
<!-- Tell SonarQube to use Jacoco as the code coverage engine to generate the reports -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<!-- Display logs to see where the analyzer spends time -->
<sonar.showProfiling>true</sonar.showProfiling>
<sonar.branch>14.1</sonar.branch>
<sonar.language>tcl</sonar.language>
<project.exclude.list>target/**</project.exclude.list>
<test.failOnError>true</test.failOnError>
<basedir>.</basedir>
<!-- Used to locate the profile specific configuration file. -->
<build.profile.id>dev</build.profile.id>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- Only unit tests are run by default. -->
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
<!-- Define where the jacoco reports are output -->
<jacoco.it.execution.data.file>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.data.file>
<jacoco.ut.execution.data.file>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.data.file>
<jacoco.it.execution.destfile>${project.build.directory}/coverage-reports/jacoco-it.exec</jacoco.it.execution.destfile>
<jacoco.ut.execution.destfile>${project.build.directory}/coverage-reports/jacoco-ut.exec</jacoco.ut.execution.destfile>
</properties>
<!-- Creating profiles for Development and Integration Testing
'dev' profile (default): used during development, only unit tests are run.
'integration-test' profile: used to run integration tests. -->
<profiles>
<profile>
<id>dev</id>
<!-- Dev profile is active by default -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!--Used to locate the profile specific configuration file-->
<build.profile.id>dev</build.profile.id>
<!-- Only unit tests are run by default. -->
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
<build>
<filters>
<!--Specifies path to the properties file, which contains profile specific configuration-->
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>integration-test</id>
<properties>
<!--Used to locate the profile specific configuration file-->
<build.profile.id>integration-test</build.profile.id>
<!-- Only integration tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
<build>
<filters>
<!-- Specifies path to the properties file, which contains profile specific configuration. -->
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
</build>
</profile>
<profile>
<id>all-tests</id>
<properties>
<build.profile.id>all-tests</build.profile.id>
<!-- All tests are run. -->
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
</profiles>
<build>
<finalName>maven-integration-testing</finalName>
<sourceDirectory>.</sourceDirectory>
<testSourceDirectory>test/tcl</testSourceDirectory>
<filters>
<filter>profiles/${build.profile.id}/config.properties</filter>
</filters>
<resources>
<resource>
<filtering>true</filtering>
<directory>.</directory>
<includes>
<include>*.tcl</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<filtering>true</filtering>
<directory>test/tcl</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>1.5</compilerVersion>
<source>1.5</source>
<target>1.5</target>
<showWarnings>true</showWarnings>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.8.1</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<!-- States that the plugin's add-test-source goal is
executed at generate-test-sources phase. -->
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<!-- Configures the source directory of integration tests -->
<sources>
<source>test/tcl</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- Use the Surefire Maven plugin to run our unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.16</version>
</dependency>
</dependencies>
<configuration>
<!-- Sets the VM argument line used when unit tests are run.
we want to create a code coverage report for our unit tests,
we have to ensure that the JaCoCo agent is running
when our unit tests are run -->
<argLine>${surefireArgLine}</argLine>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<skipTests>${skip.unit.tests}</skipTests>
<includes>
<include>test/tcl/*.tcl</include>
</includes>
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
<properties>
<property>
<name>listener</name>
<value>org.sonar.java.jacoco.JUnitListener</value>
</property>
</properties>
</configuration>
</plugin>
<!-- Failsafe Maven plugin is used to execute our integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<!-- States that both integration-test and verify goals
of the Failsafe Maven plugin are executed. -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- we want to create a code coverage report for our integration tests,
we have to ensure that the JaCoCo agent is running
when our integration tests are run -->
<argLine>${failsafeArgLine}</argLine>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<!-- JaCoCo Maven Plugin
1) provides us an access to the JaCoCo runtime agent which records
execution coverage data.
2) creates code coverage reports from the execution data recorded
by the JaCoCo runtime agent.
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<!-- Make the agent run before the tests are run -->
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!-- Make sure that the jacoco report task is run when package is executed -->
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.ut.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--Ensures that the code coverage report for unit tests is
created after unit tests have been run. -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.ut.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<!-- Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Failsafe plugin is executed. -->
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.it.execution.data.file}</destFile>
<!-- Sets the name of the property containing the settings for JaCoCo runtime agent.-->
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests after integration tests have been run.-->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${jacoco.it.execution.data.file}</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- TESTING DEPENDENCIES -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
</project>
.
**output**:
[INFO] ------------------------------------------------------------------------
[INFO] Building Code Coverage - Maven and JaCoCo running tests 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (jacoco-initialize) # example-java-maven ---
[INFO] surefireArgLine set to -javaagent:.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=/util/target/coverage-reports/jacoco-ut.exec
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (pre-unit-test) # example-java-maven ---
[INFO] surefireArgLine set to -javaagent:.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=/util/target/coverage-reports/jacoco-ut.exec
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) # example-java-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 41 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # example-java-maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-test-source (add-integration-test-sources) # example-java-maven ---
[INFO] Test Source directory:util/test/tcl added.
[INFO]
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) # example-java-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # example-java-maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.16:test (default-test) # example-java-maven ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (post-unit-test) # example-java-maven ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
[INFO] --- maven-jar-plugin:2.2:jar (default-jar) # example-java-maven ---
[INFO] Building jar:util/target/maven-integration-testing.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (jacoco-site) # example-java-maven ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (pre-integration-test) # example-java-maven ---
[INFO] failsafeArgLine set to -javaagent:.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=util/target/coverage-reports/jacoco-it.exec
[INFO]
[INFO] --- maven-failsafe-plugin:2.16:integration-test (integration-tests) # example-java-maven ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (post-integration-test) # example-java-maven ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
[INFO] --- maven-failsafe-plugin:2.16:verify (integration-tests) # example-java-maven ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-install-plugin:2.3:install (default-install) # example-java-maven ---
[INFO] Installing util/target/maven-integration-testing.jar to .m2/repository/org/codehaus/sonar/example-java-maven/1.0-SNAPSHOT/example-java-maven-1.0-SNAPSHOT.jar
[INFO] Installing util/pom.xml to .m2/repository/org/codehaus/sonar/example-java-maven/1.0-SNAPSHOT/example-java-maven-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.054s
[INFO] Finished at: Fri Jan 03 13:35:38 GMT 2014
[INFO] Final Memory: 12M/132M
[INFO] ------------------------------------------------------------------------
>
EDIT:
Also, I wonder if Maven works for projects not with Java code.
Is there any way to make it support a scripting language? And run its tests?

maven-failsafe-plugin Errors and BUILD SUCCESS?

my question is very similar to this one: maven-failsafe-plugin Failures and BUILD SUCCESS?
and I manage to set up failsafe plugin to fail if tests fail.
But if test goes into error state, failsafe plugin still does not break the build.
.................
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running xxxxx.IntegrationTierFunctionalTestCase
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.054 sec <<< FAILURE!
Results :
Tests in error:
testException(xxxxx.IntegrationTierFunctionalTestCas
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is
[INFO] [failsafe:verify {execution: functional-test-1024}]
[INFO] Failsafe report directory: C:\projects\oec-integration-server\trunk\oec-integrati
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is
[INFO] [failsafe:integration-test {execution: functional-test-24}]
[INFO] Failsafe report directory: C:\projects\oec-integration-server\trunk\oec-integrati
.............
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 58 seconds
[INFO] Finished at: Tue May 28 17:48:13 BST 2013
[INFO] Final Memory: 114M/781M
[INFO] ------------------------------------------------------------------------
for simplicy IntegrationTierFunctionalTestCase contains only this code
import org.junit.Test;
import static org.junit.Assert.fail;
public class IntegrationTierFunctionalTestCase
{
#Test
public void testException(){
//fail();
throw new RuntimeException("super error");
}
}
if I uncomment fail() whole build fails correctly, with build failed.
but if I just throw an exception, it fails as on shown above.
oour plugin configuration looks like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.7</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemPropertyVariables>
<oec.env>TEST</oec.env>
<mule.test.timeoutSecs>2400</mule.test.timeoutSecs>
</systemPropertyVariables>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/resources/config</additionalClasspathElement>
</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<executions>
<execution>
<id>functional-test-1024</id>
<phase>test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/IntegrationTierFunctionalTestCase.java</include>
</includes>
<forkMode>once</forkMode>
<argLine>-XX:MaxPermSize=256M -Xmx1024M</argLine>
</configuration>
</execution>
</executions>
</plugin>
What am I missing?
And no I do not want to wrap it in try-catch blocks and fail tests manually.
You need having two executions blocks, cause the verify goal of the maven-failsafe-plugin is intended to check the results of the integration tests.
<executions>
<execution>
<id>functional-test-1024</id>
<phase>test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/IntegrationTierFunctionalTestCase.java</include>
</includes>
<forkMode>once</forkMode>
<argLine>-XX:MaxPermSize=256M -Xmx1024M</argLine>
</configuration>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
Furthermore you should update the version of the maven-failsafe-plugin to 2.14.1 instead of 2.7.
Update: In the meantime update to 2.17.
If you're running the integration tests like this:
mvn test-compile failsafe:integration-test
Then you should know that according to the maven documentation on failsafe:
The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.
I was able to get the build to fail like this:
mvn test-compile failsafe:integration-test failsafe:verify
And here's my failsafe configuration for reference:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
Please verify that the maven property "maven.test.failure.ignore" is not set to "true" in any of your maven pom.xml files, as it can be the only reason to not stop the build after test failure.
There is one possible additional reason why it happens. Failsafe verify is looking for test classes and expects them to be in ${project.build.directory}/test-classes - if you have a different setup it will just print "No tests to run." and ends if build success regardless of what the result of integration-test phase was.
You have to set testClassesDirectory in plugin configuration :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<environmentType>${environmentType}</environmentType>
</systemPropertyVariables>
<summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary.xml</summaryFile>
<testClassesDirectory>${project.build.directory}/classes</testClassesDirectory>
<suiteXmlFiles>
<suiteXmlFile>${suiteXml}</suiteXmlFile>
</suiteXmlFiles>
</configuration>

Disable maven plugins when using a specific profile

I'm looking to find a way of disabling a plugin execution if running with a particular profile.
This is the opposite of running a plugin if a profile is selected.
My use case: My Maven build has a whole load of plugins, but when running on my dev machine, I want to skip some of them. Instead of commenting those plugins out locally, I want to be able just run the build with a "dev" profile. The plugins would continue to run on my continuous build.
Ideas?
There is a neat way to disable plugin execution when specific profile is active.
Firstly you need to add an identifier to plugin execution like:
<build>
<plugins>
<!-- (...) -->
<plugin>
<groupId>nl.geodienstencentrum.maven</groupId>
<artifactId>sass-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>styles-compilation</id> <!-- plugin execution identifier -->
<phase>generate-resources</phase>
<goals>
<goal>update-stylesheets</goal>
</goals>
</execution>
</executions>
</plugin>
Then you need to define a profile in which this plugin will NOT be executed:
<profiles>
<profile>
<id>no-sass</id>
<build>
<plugins>
<plugin>
<groupId>nl.geodienstencentrum.maven</groupId>
<artifactId>sass-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>styles-compilation</id> <!-- here there must be the same identifier as defined in <build><plugins> section -->
<phase>none</phase> <!-- this disables plugin -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Now if you run standard maven build:
mvn clean package
the sass-maven-plugin will be executed, yet when running:
mvn clean package -P no-sass
the sass-maven-plugin will not be executed.
Define your pom so that is has only the plugins you need in dev mode
Define a dev profile
Define a production profile which contains all plugins you want/need
Define the production profile as default
example pom:
<profiles>
<profile>
<id>production</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<!--
<plugin>
...
</plugin>
-->
</plugins>
</build>
</profile>
<profile>
<id>dev</id>
<!-- Some other logic here, if necessary.
Otherwise, there's no need for another profile. -->
</profile>
</profiles>
To run in Dev Mode you can call the following:
mvn -Pdev compile
To run in Production Mode just use the normal steps:
mvn compile
In case you don't want/need to define anything special in your dev profile, you can omit its declaration and call your Dev Mode like this (! disables a profile):
mvn -P!production compile
Be aware: you may need to escape the exclamation mark since it is a special character in bash:
mvn -P\!production compile
Building on Krzysiek's answer, you don't need to define explicit executions, just have a look at the output maven gives you and disable the default executions.
For instance, given the following output from maven:
[INFO] --- maven-resources-plugin:2.7:copy-resources (prepare-dockerfile) # tilbud ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
...
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) # tilbud ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
....
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # tilbud ---
...
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) # tilbud ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
...
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) # tilbud ---
....
The generated default execution names is listed in parenthesis after the plugin and goal. The following profile disables the plugins above:
<profiles>
<profile>
<id>packageOnly</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-resources</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testResources</id>
<phase>none</phase>
</execution>
<execution>
<id>prepare-dockerfile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>

Resources