Hey, I'm talking about profiles within pom.xml of a project. Could please anybody explain to me, why if I have 2 profiles in pom definition and I run test phase from one of the profiles, both the Main method is executed and all the tests are run by surefire plugin ? I mean, even the surefire plugin runs all the tests, even though it is within a different profile ?
mvn test -Pcode-generator
the first one,code-generator, is just for Main methods execution and the second one for the rest of the project.
<profiles>
<profile>
<id>code-generator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>cz.instance.transl.Main</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>default</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<warName>${war.file.name}</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<useFile>false</useFile>
<argLine>-Dportal.test=generic
-Dwebdriver.chrome.driver="/opt/google/chrome/chromedriver"
-Dwebdriver.development=true
-Dwebdriver.firefox.useExisting=true
-Dwebdriver.firefox.profile=webdriver
-Dwebdriver.reap_profile=true
-Dsurefire.useFile=false
-Xmx2048M
-XX:MaxPermSize=1048M
-XX:+CMSClassUnloadingEnabled
</argLine>
<skipTests>false</skipTests>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>META-INF/log4j.xml</value>
</property>
</systemProperties>
<includes>
<include>cz/instance/transl/tests/selenium/*Test.java</include>
</includes>
<excludes>
<exclude>cz/instance/transl/tests/sample/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.7.1</version>
<!-- <configuration> <useFile>false</useFile> </configuration> -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
<includes>
<include>**/*.*</include>
</includes>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
<resources>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>service.properties</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>profiles/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
The surefire plugin is one that runs by default for a java project. You have a number of options:
Add the surefire plugin to your code-generator profile and override it not to run.
Run with -DskipTests.
Specify only the goal you want to run, instead of running a full maven build.
Related
I'm creating a testing framework with Java 11 and Maven, and I have build two different runners for separate tests. I want to run only one profile but it keeps running both of them. Here are my profiles:
<profiles>
<profile>
<id>smoke</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>smoke</id>
<configuration>
<includes>
<include>**/SmokeRunnerTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>functional</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>functional</id>
<configuration>
<includes>
<include>**/FunctionalRunnerTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
You can put
<activation>
<activeByDefault>false</activeByDefault>
</activation>
into profiles' definition to avoid unneeded profile activation.
I have profile configuration in my POM with surefire-maven-plugin & junit connection to run only specific tests by profile. For example:
mvn clean test -Pgroup1 --also-make -DfailIfNoTests=false
It works as expected with following versions:
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
<junit.version>4.12</junit.version>
But stops working normally when I try to upgrade them:
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<junit.version>4.13</junit.version>
In this case mvn test always run all tests as I wouldn't set profile in command line.
My config of profiles is:
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/unit/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>group1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/unit/**</exclude>
</excludes>
<groups>com.Group1</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>group2</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/unit/**</exclude>
</excludes>
<groups>com.Group2</groups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
......................
</profiles>
Every test class has connected interface linked to profile:
#Category(Group1.class)
#RunWith(JUnitParamsRunner.class)
public class Group1Test {
Playing with 'default' profile and 'activeByDefault' property also gave me no result. Any ideas how to fix it?
I got this to work by using "executions" in both the default plugin and in the profile plugin (which is not, by the way, an override of the default one)
<project>
...
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M8</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals><goal>test</goal></goals> <!-- REQUIRED -->
<configuration>
<enableAssertions>true</enableAssertions>
<systemPropertyVariables>
<log4j.debug>true</log4j.debug>
<client.test.url>http://localhost:8080/axis/services/MyService</client.test.url>
</systemPropertyVariables>
<excludes>
<exclude>**/TestAccountOp</exclude> <!-- Tomcat required - use the profile -->
<exclude>**/TestWsdl</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>myprofileid-testwithtomcat</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M8</version>
<executions>
<execution> <id>default-test</id> <phase>none</phase> </execution> <!-- Disable default Maven execution -->
<execution>
<id>myexecutionid-testwithtomcat</id>
<phase>test</phase>
<goals><goal>test</goal></goals> <!-- REQUIRED -->
<configuration>
<enableAssertions>true</enableAssertions>
<systemPropertyVariables>
<log4j.debug>true</log4j.debug>
<client.test.url>http://localhost:8080/axis/services/MyService</client.test.url>
</systemPropertyVariables>
<excludes>
<exclude>**/TestWsdl</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
...
</profiles>
</project>
In the profile, I removed the "default-test", otherwise the "excludes" were set from the default one, but that might have been before I moved the "configurations" into the "executions". You have to remember that "default-test" is active unless you disable it, but not using an "execution" in the main body did not work for me.
"default-test" is Maven's "id" for the one in the main body, so that is why I used that name in the "execution" in the main body.
I think you can get away with not bothering with the "phase" elements, because that's the default for the "test" goal, but I'm pretty sure that you need the goal.
Good luck!
I am trying to create single fat jar using maven assembly plugin but somehow after running maven clean install it give 2 jars, one is client-1.0-SNAPSHOT.jar and other one is client-1.0-SNAPSHOT-jar-with-dependencies.jar.
I am only interested to create a jar with dependencies so dont know why the other jar is also creating by this assemble plugin.
Can someone tell me how to eliminate this jar Or should i use some other maven command rather than clean install ?
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
-->
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.app.MainApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- overwrite! -->
<overwrite>true</overwrite>
<outputDirectory>${project.basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
i need to change multiple xml file while build a war using maven like below example
I am able to do the required change in the target folder. But It is not copied in to the war file
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
<id>dse xml replacer</id>
<configuration>
<file>
${project.artifactId}/target/${project.artifactId}-${version}/WEB-INF/example.xml
</file>
<replacements>
<replacement>
<token>reloadingEnabled=".*"</token>
<value>reloadingEnabled="false"</value>
</replacement>
</replacements>
</configuration>
</execution>
</plugin>
Try the maven-war-plugin, like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>resource2</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
More info https://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
When I'm going to Maven-install my project with pom
<build>
<defaultGoal>package</defaultGoal>
<sourceDirectory>${basedir}/src/main/izpack</sourceDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/izpack</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- Configure the compiler to use Java 1.5 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<!-- Have project dependencies be picked up by izPack when its compiler runs -->
<plugin>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>5.0.0-rc4</version>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-panel</artifactId>
<version>5.0.0-rc4</version>
</dependency>
</dependencies>
<!-- mvn help:describe -DgroupId=org.codehaus.izpack -DartifactId=izpack-maven-plugin -Dversion=5.0.0-beta11 -Ddetail -->
<configuration>
<installFile>${staging.dir}/install.xml</installFile>
<attach>false</attach>
<kind>standard</kind>
<descriptorEncoding>UTF-8</descriptorEncoding>
<izpackBasedir>${staging.dir}</izpackBasedir>
<customPanelDirectory>${staging.dir}</customPanelDirectory>
</configuration>
<executions>
<execution>
<id>standard-installer</id>
<phase>package</phase>
<goals>
<goal>izpack</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Do not deploy any of the installer artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<staging.dir>${project.build.directory}/staging</staging.dir>
</properties>
Failed to execute goal org.codehaus.izpack:izpack-maven-plugin:5.0.0-rc4:izpack (standard-installer) on project Izpack-Installer: Failure during compilation process: Invalid base directory: workspace/myproject/target/staging
The above error is making my whole day waste... please post working pom of izpack Maven plugin which support console installation in Linux.
Note: I placed my install.xml in src/main/izpack/install.xml as well as src/main/resources/install.xml.
Finally after end of the day got answer...:)
<build>
<defaultGoal>package</defaultGoal>
<sourceDirectory>${basedir}/src/main/resources</sourceDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- Configure the compiler to use Java 1.7 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Have project dependencies be picked up by izPack when its compiler runs -->
<plugin>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-maven-plugin</artifactId>
<version>5.0.0-rc4</version>
<configuration>
<installerFile>${basedir}/target</installerFile>
<izpackBasedir>${staging.dir}</izpackBasedir>
<dependencies>
<dependency>
<groupId>org.codehaus.izpack</groupId>
<artifactId>izpack-standalone-compiler</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
</configuration>
<executions>
<execution>
<id>izpack</id>
<phase>package</phase>
<goals>
<goal>izpack</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Do not deploy any of the installer artifacts. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<staging.dir>${project.build.directory}/staging</staging.dir>
</properties>
"staging" directory in target folder is created manually....:)