Maven + Surefire: Overwrite temp and output directory - maven

I am trying to overwrite temporary and output directory for surefire plugin. I have following plugin definition:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<tempDir>c:/tmp/a-tests-temp</tempDir>
<outputDirectory>c:/tmp/a-tests-out</outputDirectory>
</configuration>
</plugin>
It does not work. It continue using /target/surefire and target/surefire-reports.
The idea is to split different concurrency maven test runs over the same project directory for quick tests on the developer workstation.

Sorry for late reply, ive only managed to use relative path location to change the path for the temp folder
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<testClassesDirectory>${project.buildDirectory}/test-classes</testClassesDirectory>
<reportsDirectory>${project.buildDirectory}/surefire-reports</reportsDirectory>
<classesDirectory>${project.buildDirectory}/test-classes</classesDirectory>
<tempDir>../${project.buildDirectory}/surefire</tempDir>
<useFile>false</useFile>
<includes>
<include>**/*Spec.*</include>
</includes>
<systemPropertyVariables>
<geb.env>${geb.env}</geb.env>
<geb.build.reportsDir>${project.buildDirectory}/${geb.build.reportsDir}</geb.build.reportsDir>
<com.athaydes.spockframework.report.outputDir>${project.buildDirectory}/spock-reports</com.athaydes.spockframework.report.outputDir>
<com.athaydes.spockframework.report.aggregatedJsonReportDir>${project.buildDirectory}/spock-reports</com.athaydes.spockframework.report.aggregatedJsonReportDir>
</systemPropertyVariables>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>

Related

Running just one Test suites with Maven not working

I have in my pom.xml two test suites
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<file>src/test/resources/weekly.xml</file>
<file>src/test/resources/monthly.xml</file>
<!-- <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> -->
</suiteXmlFiles>
</configuration>
</plugin>
When I'm trying to run only one from the command line with mnv test -Dsurefire.suiteXmlFile=src/test/resources/monthly.xml
Is running both of them and generate repost for both of them.
How can I run only one xml?
I just checked and executed the pom.xml. If you want to pass the xml file location at the runtime, your pom.xml should look like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
You can use the maven command mentioned as below to execute :
mvn test -DsuiteXmlFile=src/test/resources/.xml

How can I exclude certain overlay-derived directories from my war using maven?

We build a webapp using maven 3.5.0 and the maven-war-plugin. We have many overlays, many of which have a tests directory that contains JSP files used for testing certain things in a dev environment. We don't want these included in our war.
We tried the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<overlays>...</overlays>
<warSourceExcludes>tests</warSourceExcludes>
</configuration>
</plugin>
This didn't work, nor did a couple of configuration variations:
<packagingExcludes>tests</packagingExcludes>
and
<packagingExcludes>**/${project.artifactId}/tests/**</packagingExcludes>
Is this due to my naive misuse of configuration options, or does it have to do with how overlays are processed?
You should use <excludes>..</excludes> (see https://maven.apache.org/plugins/maven-war-plugin/overlays.html) instead of <packagingExcludes>..</packagingExclude>...
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<overlays>
<overlay>
<groupId>com.example.projects</groupId>
<artifactId>documentedprojectdependency</artifactId>
<excludes>
<exclude>WEB-INF/classes/images/sampleimage-dependency.jpg</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
...
The dependentWarExcludes element worked to eliminate the tests directories and their contents:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<overlays>...</overlays>
<dependentWarExcludes>tests/**</dependentWarExcludes>
</configuration>
</plugin>

How to get the icons for the resulted maven-surefire-report-plugin

I'm using maven-surefire-report-plugin in order to generate the unit tests report.
This is working fine however the report contains links to images which are not presented.
How can I make maven copy the icons required for the report?
Should I use skin? I tried it without success.
Here is the maven-surefire-report-plugin definition:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
<configuration>
<showSuccess>true</showSuccess>
</configuration>
</plugin>
</plugins>
</reporting>
I tried to add skin plugin but it didn't affect the report:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-application-skin</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
What is missing to present the report with the images?
The question is probably too old, but I had the same problem and I found this answer.
The command mvn site -DgenerateReports=false generates only css and images for surefire-report.html and works fine.
You must genereate the site using the Site Plugin:
mvn site
If you have already generated the reports, then you can speed this up by skipping this:
mvn site -DgenerateReports=false
mvn site -DgenerateReports=false
I did it like this, but it's a hack:
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<testSourceDirectory>src/test/java</testSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<linkXRef>false</linkXRef>
<showSuccess>true</showSuccess>
</configuration>
<executions>
<execution>
<id>generate-test-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.basedir}/src/test/resources/css</directory>
<targetPath>${project.build.directory}/site/css</targetPath>
<includes>
<include>*.css</include>
</includes>
</resource>
</resources>
</build>

Maven: excluding java files in compilation

I have a folder of java sources which I wish to exclude from the compilation.
My folder is under qa/apitests/src/main/java/api/test/omi.
I added the following entry in the pom.xml under qa/bamtests but it didn't help. Is there an entry in addition I need to make?
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.xsd</include>
<include>**/*.csv</include>
</includes>
<excludes>
<exclude>src/main/java/api/test/omi</exclude>
</excludes>
</resource>
</build>
Use the Maven Compiler Plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/api/test/omi/*.java</exclude>
</excludes>
</configuration>
</plugin>
Adding an exclude as the other answers suggested worked for me, except the path shouldn't include "src/main/java":
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>com/filosync/store/StoreMain.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
For anyone needing to exclude test sources <exclude> tag will not work. You need to use <testExclude> instead:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<testExcludes>
<testExclude>**/PrefixToExclude*</testExclude>
</testExcludes>
</configuration>
</plugin>
If you want to exclude the java sources from compiling, then mention them in the Maven Compiler Plugin definition
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<excludes>
<exclude>src/main/java/api/test/omi/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
The resources plugin only defines what all resources to bundle in your final artifact.
The top voted answer works fine but it doesn't allow forcing the exclusion when the excluded class/classes is/are being used by not-excluded ones.
Workaround using maven-antrun-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<tasks>
<delete dir="target/classes/folder/to/exclude"/>
</tasks>
</configuration>
</plugin>

How to set up an environment variable in mvn pom?

How can i set up an environment variable (in other words internally accessible by System.getenv("APP_HOME") in a pom file?
APP_HOME=/path/home
I realize i can set it up in .profile, but wonder if pom can do the same trick.
Per bmargulies's suggestion below, i tried the following, without luck
<build>
<finalName>KvpStore</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/*Test*.java</include>
</includes>
<environmentVariables>
<APP_NAME>blah_blah</APP_NAME> <------------------------
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
Some plugins, like surefire, let you set them. There's no way, in general, in the pom.
The doc for surefire is is here. Surefire will set environment variables for the duration of the run of the tests, not for anything else. And you have to make surefire fork.
In the configuration ...
<configuration>
<forkMode>always</forkMode>
<environmentVariables>
<var1>val1</var1>
</environmentVariables>
</configuration>
The documentation of the maven-surefire-plugin show examples and describes how to do such things of setting up system properties.
<configuration>
<systemPropertyVariables>
<propertyName>propertyValue</propertyName>
<buildDirectory>${project.build.directory}</buildDirectory>
[...]
</systemPropertyVariables>
</configuration>
It might be better to use them instead of environment variable, cause it's simpler to use them, cause env variable needed to setup correctly and the cmd.exe and the jvm must be restarted to get them working.
It is not necessary to configure the includes for the tests, cause maven-surefire-plugin has already the following defaults:
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>

Resources