From Maven Surefire Plugin docs:
If you have multiple executions configured in surefire plugin within your POM, you may want to execute the only default test phase:
mvn surefire:test -Dtest=TestCircle
I didn't understand what is the priority/overriding between the POM config and the command-line.
I have these plugin configurations in my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
Now I'm trying to run my tests with
mvn test -Dsurefire.includesFile=.\Path\To\includesFile -Denv=IsProfileValueTag
And I'm expecting only the classes in the includesFile to run, but all the tests with the IsProfileValueTag running.
Related
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<suiteXmlFiles>
<!-- pass testng.xml files as argument from command line -->
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
How to pass this variable now with mvn command?
Tried:
mvn clean install test -DsuiteXmlFile=testng-suite.xml
mvn clean test -Dsurefire.suiteXmlFiles=testng-suite.xml
Always getting the error, seems like connected to . (dot) symbol not treated as expected:
Unknown lifecycle phase ".xml". You must specify a valid lifecycle
phase or a goal in the format : or...
Unknown lifecycle phase ".suiteXmlFiles=testng-suite.xml". You must
specify a valid lifecycle phase or a goal
Same problem have when passing any properties - treats dot as some lifecycle phase...
do it like this
mvn -DsuiteXmlFile=testng-suite.xml clean install test
mvn -Dsurefire.suiteXmlFiles=testng-suite.xml clean test
I'm trying to deploy a maven project and upgrade the versions by executing the maven release plugin on TeamCity. I am able to successfully do this - however, the resources:resources plugin is no longer executed. Or more accurately, it is executed but not doing the expected changes. When I run a maven package or install however, it works. Not sure what it is I'm missing. Any help would be appreciated.
Below is my code
Parent pom
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagNameFormat>v#{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
<releaseProfiles>releases</releaseProfiles>
<localCheckout>true</localCheckout>
<arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%</arguments>
</configuration>
<executions>
<execution>
<id>prepare</id>
<goals>
<goal>prepare</goal>
</goals>
<configuration>
<pushChanges>false</pushChanges>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Child pom
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<!-- Adds ${buildNumber} to buildNumber.properties -->
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application_local.properties</exclude>
</excludes>
</resource>
</resources>
</build>
I run the following command:
mvn -B -e initialize release:branch release:clean release:prepare release:stage -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%...
And I have in my child project in the src/main/resources folder a file called application-deployed.properties with the following lines which is what I want to change.
# build information by team city
child.propject.buildNumber=#CONTINUOUS_BUILD_ID#
child.propject.buildVersion=#GIT_COMMIT#
child.propject.buildBranch=#GIT_BRANCH#
Any help is much appreciated
maven-resources-plugin doesn't have access to the parameters you pass in the command line. Reason for this is that deploy goal (which includes resources:resources, among others) is invoked by maven-release-plugin in a separate Maven execution.
In order to overcome this limitation, goals of maven-release-plugin accept arguments parameter that could be used to pass parameters to aforementioned separate Maven executions. Try to modify your command line the following way:
mvn -B -e initialize release:branch release:clean release:prepare release:stage -Darguments="-DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%"
I was able to solve the issue by adding the following to the maven release plugin in the parent pom
<arguments>-Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -DCONTINUOUS_BUILD_ID=${CONTINUOUS_BUILD_ID} -DGIT_COMMIT=${GIT_COMMIT} -DGIT_BRANCH=${GIT_BRANCH}</arguments>
and then calling my initial command
mvn -B -e initialize release:branch release:clean release:prepare release:stage -DCONTINUOUS_BUILD_ID=%build.counter% -DGIT_COMMIT=%build.vcs.number% -DGIT_BRANCH=%vcsroot.branch%...
I want to run my Junit on my build jar's, but maven surefire plugin executed on class file before package phase that is at test phase, is there any way to run all junit after building a jar of project.
Reason to run on build jar is to verify obfuscation of jar.
Solution is to use the maven-failsafe-plugin which will in the integration test phase. You need to this to your pom file:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
You should following the conventions and follow the naming conventions of integration tests:
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
</includes>
Afterwards you can run those integration tests via:
mvn clean verify
If you like to run only unit tests:
mvn clean test
There are two phase of tests in maven, one is unit test, second is integration tests. So if You want, You should execute it in integration tests phase.
I'm wondering if there is a way to specify in Maven which collection of JUnit tests run based on package names. An 'exclude' would be ideal, since I have fewer that I need not run than I have those that need to run.
Yes you can configure surefire plugin to include certain tests only
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<includes>
<include>com/abc/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
I imported a Maven project into IntelliJ, but it seems like it's ignoring the <configuration> specified for the surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<argLine>-Djava.endorsed.dirs=${settings.localRepository}/com/sun/metro/webservices-api/2.0.1
</argLine>
<excludes>
<exclude>**/CacheStoreTest.java</exclude>
</excludes>
</configuration>
</plugin>
When I run the tests from within the IDE, it picks up the webservices-api.jar bundled with JDK6 instead of the version from my Maven repository and it also runs the tests in CacheStoreTest even though I've indicated they should be excluded.
It's a known issue, please watch/vote.