From this page:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
under "Fully qualified class name" section, It seems possible to specify which test methods to run in pom.xml. However, it is not very clear where to write this tag called "test". Anyone could shed some lights?
Update:
You can define it inside <properties>, as in:
<project>
<properties>
<test>TestCircle#testSlow</test>
</properties>
</project>
Also, you can use includes and excludes as hinted here, e.g.:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>Sample.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
and
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
Related
I'm sure that such a question is already somewhere in internet, but I can't find it so..
I use maven-surefire-plugin.
It generates surefire-reports folder with reports in it.
I want to have different folders for each run.
I'm trying to add timestamp in report name like this:
Pom part:
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
<sourceDirectory>src/main/java</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>${project.build.directory}_${timestamp}</reportsDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
But in this case I have no surefire-reports folder at all.
Somewhere is a mistake but I have no idea where.
Can someone give me a clue about this?
That date format is not a valid directory name (especially for the the : char), maybe something like yyyy-MM-dd_HH-mm? also I would go to the target folder:
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd_HH-mm</maven.build.timestamp.format>
<sureFireDir>${project.basedir}/target/${timestamp}</sureFireDir>
</properties>
...
<reportsDirectory>${sureFireDir}</reportsDirectory>
Trying to exlcude a folder src/main/resources/scripts/ from my build but the following does not work:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>src/main/resources/scripts/</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<excludes>
<exclude>src/main/resources/scripts/</exclude>
</excludes>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Any ideas?
Instead try:
<exclude>scripts/**</exclude>
The exclude is based on directory, so your construction would exclude
src/main/resources/src/main/resources/scripts
I had a similar problem and found the following issues:
You may have a parent pom which already defines a configuration for the maven-compiler-plugin. For this, add combine.self="override" to the configuration tag. See Maven : Is it possible to override the configuration of a plugin already defined for a profile in a parent POM
It seems the plugin ignores excludes if it needs the excluded classes for the compilation: make sure you are not referencing the excluded classes from other classes which will get compiled. For example, if you exclude Foo.java, but in Bar.java you import Foo; it will (try to) compile Foo.java to compile Bar.java.
For example:
<profiles>
<profile>
<id>myId</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration combine.self="override">
<excludes>
<exclude>**/some/full/directory/*</exclude>
<exclude>**/some/single/File.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profiles>
<profile>
<id>readBuild</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration >
<excludes>
<exclude>**/com/pyramid/controllers/EntitlementWriteController.java</exclude>
<exclude>**/com/pyramid/controllers/ProductWriteController.java</exclude>
</excludes>
<testExcludes>
<testExclude>**/com/pyramid/controllers/EntitlementWriteControllerTest.java</testExclude>
<testExclude>**/com/pyramid/controllers/ProductWriteControllerTest.java</testExclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
<directory>yourDirectory</directory>
</build>
</profile>
It's so very simple and you not need add other plugin:
https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
</excludes>
</resource>
</resources>
</build>
I have ext-plugin and I would like to override this file: portal-impl\src\com\liferay\portlet\dynamicdatamapping\dependencies\ddm\documentlibrary.ftl. After maven build, this file isn't include in my porta-impl-ext.jar.
In my portal-impl-ext's pom.xml I have this code:
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.maven.plugin.version}</version>
<configuration>
<apiBaseDir>${basedir}/../my-ext-service</apiBaseDir>
<implBaseDir>${basedir}</implBaseDir>
<sqlDir>${basedir}/../my-ext/src/main/webapp/WEB-INF/sql</sqlDir>
<webappBaseDir>${basedir}/../my-ext-web</webappBaseDir>
</configuration>
</plugin>
</plugins>
</build>
In my portal-ext's pom.xml I have this:
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.maven.plugin.version}</version>
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginName>my-ext</pluginName>
<pluginType>ext</pluginType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<includes>
<include>**/*.*</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
I tried to change include section, but it didn't work. It is possible to include this file?
Thanks in advance for any help!
The solution is moving file from source folder to resource folder.
I have a maven project for a webapp, which repack war dependency using overlays. For two profiles, test and prod, it should exclude demo.jsp file, but for other, for example local, this file should stay. Is there a way to have only one configuration for two profiles? I don't want to repeat one configuration for two profiles.
My current solution:
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<excludes>
<exclude>demo.jsp</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<excludes>
<exclude>demo.jsp</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
EDIT: test and prod profiles are identical
The Plugin Management may help us as the following :-
<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>mygroup</groupId>
<artifactId>mywebapp</artifactId>
<excludes>
<exclude>demo.jsp</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</pluginManagement>
</build>
Then the profiles should be as the following: -
<profiles>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
...
</profile>
<profile>
<id>prod</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
...
</profile>
</profiles>
I hope this may help.
I'm trying to write a parent pom, and I have a plugin defined, but I need to change the config for all inherited instances. So, I can put some configuration in the <pluginManagement> definition, and I can override it in the <plugin>, but how do I get the children to default back to the <pluginManagement> version?
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions...>
<configuration>
<configLocation>
(used by all children)
</configLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>
(unique to the parent)
</configLocation>
</configuration>
</plugin>
</plugins>
<build>
So, what happens is the children continue to show the parent's config.
Ok, I think I have it. The answer, in my case, relates to what you specified - I did need the tag. However the solution was in the tag; by binding it to a non-phase, it does execute. This I knew. What I discovered is that the had to match in order for it to override. Thus, the config never gets parsed and doesn't matter.
<build>
<pluginManagement>
<plugins>
<plugin>
<!-- Main declaration of the plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<!--This must be named-->
<id>checkstyle</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration...>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<!-- Uses the default config -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<!--This matches and thus overrides-->
<id>checkstyle</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can explicitly specify in your parent pom that the plugin should not be inherited:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<executions...>
<configuration>
<configLocation>
(used by all children)
</configLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<inherited>false</inherited> <!-- Add this line -->
<configuration>
<configLocation>
(unique to the parent)
</configLocation>
</configuration>
</plugin>
</plugins>
<build>
And in your child pom, you need to specify the plugin (the config will then come from the <pluginManagement> parent element.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
<build>