I want to skip integration tests while running maven release plugin with command
mvn -B -DskipITs release:prepare release:perform
It does not seem to work this way. The same option -DskipITs works for mvn install/deploy. I don't want to use -Dmaven.test.skip=true since only integration tests need to be ignored, not unit tests. What is the best way to accomplish this?
EDIT:
-Darguments=-DskipITs works for release:prepare, but surprising it does NOT work for release:perform. Tried -Darguments=-Dmaven.test.skip=true, does not work either.
Tried to add <arguments>skipITs</arguments> for release plugin in the pom, but it would ignore all other -Darguments provided in command line. I can't have everything configured in plugin config, since some of the options takes environment variables on the fly.
According to how to make maven release plugin skip tests, it seems you need both -DskipITs and -Darguments=-DskipITs. One is to skip compiling ITs the other is for skipping running ITs.
Use Maven Profiles.
Add the following to your pom:
<profiles>
<profile>
<id>ItsReleaseTime</id>
<build>
<plugins>
<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>
</profile>
</profiles>
And invoke the command :
mvn -B -P ItsReleaseTime release:prepare release:perform
You can add some setting in your pm.xml file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
Related
I am trying to run some vulnerability scans(Veracode) on a spring boot application. However, the scan provider suggests running the scans with binaries compiled in debug mode using the following in pom.xml file.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
</plugins>
</build>
However, we use the same pom.xml for production deployment where we don't want debug level jars.
Is there a way to create debug jars by passing some argument to the mvn command?
You can use profiles.
<profiles>
<profile>
<id>debug</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profile>
Profiles are activated in the mvn command, e.g., mvn ... -Pdebug.
I think it is possible to set the arguments in the command line with -D like this:
mvn compile -Dmaven.compiler.debug=true -Dmaven.compiler.debuglevel=lines,vars,source
I have written the test cases but it is activating when I am running the mvn clean install test cases also running but my case no need to run the test cases while running the mvn clean install when I am using the particular profile then only activate the test cases.
You can configure surefire plugin in your pom.xml to include/exclude tests based on their names, and use different configuration for the profiles you want to run these tests on.
Something like:
<profiles>
<profile>
<id>without-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludes>
<exclude>**/someTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>without-other-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<excludes>
<exclude>**/otherTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
See more about it here
Name the tests you dont want to run with a suffix that enables you to group them ...
e.g. sometimes we use ...FunctionalTest to label functional tests. These tests can then be grouped/included/excluded when running unit tests, as a part of the standard build.
See this post for more info How to permanently exclude one test class in a Maven build
I'm looking for a Maven plugin that could execute by itself the good JVM arguments.
For now, I've tried using the maven-compiler-plugin and the maven-surefire-plugin (the pom of my project is down below).
the type of argument I want the jvm to execute is this one:
--module-path="C:\Program Files\Java\javafx-sdk-11\lib" --add-modules=javafx.controls
in order to launch a javafx app.
the pom.xml with the plugin tests.
<build>
<plugins>
//tests with the surefire plugin (without tests).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<skipTests>true</skipTests>
<argLine>--module-path="C:\Program Files\Java\javafx-sdk-11\lib" --add-modules=javafx.controls</argLine>
</configuration>
</plugin>
</plugins>
</build>
My Project dosnt have a bin folder
Have tried the following:
D:>java -cp "Pathtolibfolder\lib*;Pathtobinfolder\bin"
org.testng.TestNG testng.xml
Any Ideas?
If you are using Maven then i would simply use the surefire plugin and run tests as part of the build:
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>RELEASE</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
...
</plugins>
Just specify the path to your testng.xml and take advantage of it if you can use this kind of configuration.
It allows for tons of parametrization and i have used it extensively in my projects.
Check out this tutorial to get a hang of it: http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html
I have some classes I'm using as tests in my src/test/java folder of my project. When I run maven using the standard maven compile plugin. Those items are compiled into .class files and are included in the jar where the compiled code is packaged.
I've created these tests for myself to run within eclipse, prior to running maven and building my release. They are just sanity tests and should not be included in the build. I'd rather not put them in a seperate project, because, to me, they make sense here. How can I tell maven that I do not want it to compile/include the files in that directory?
I beleive the maven compiler plugin is generating the jar as follows:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
I understand from your comment on this answer that the "tests" aren't unit tests, but just ordinary classes that you want excluded from the final artifact? As such, your best option is to make use of the <exclude> tag with the maven-jar-plugin as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**/yoursortoftestpackage/YourSortOfTestClass*</exclude>
</excludes>
</configuration>
</plugin>
Hope that helps!
Cheers,
Use the option of -Dmaven.test.skip will skip both compilation and execution of the tests. ( use -DskipTests just skips the test execution, the tests are still compiled)
The reference link
mvn clean install -Dmaven.test.skip
Annotation for junit #Ignore will ignore the class while building in maven.
Edit:
You can configure maven-surefire-plugin.
<project>
<build>
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
Put your custom test files in a folder src/localtest/java i think, maven will not know it is there.