It is in my understanding that when a profile is explicitly set with the -P option, it is exclusive and that profile should get activated no matter what.
In my case, after running the command mvn clean compile -Pcross-compile, the cross-compile profile was ignored and build-linux-amd64 was activated instead.
What is going on here and why is cross-compile not being called?
My profile configuration below:
<profiles>
<!-- Cross-compile profile (can only be run under linux os) -->
<profile>
<id>cross-compile</id>
<properties>
<current-os>linux</current-os>
<current-arch>amd64</current-arch>
<crossCompile>true</crossCompile>
<build-target>native-build-cc-all</build-target>
</properties>
<build>
<plugins>
<!-- Enforcer: Make sure this can only be run from the Linux OS -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-os</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireOS>
<name>Linux</name>
<family>unix</family>
<arch>amd64</arch>
</requireOS>
</rules>
<failFast>true</failFast>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- BUILD PROFILE: Linux - x86_64/amd64 -->
<profile>
<id>build-linux-amd64</id>
<activation>
<os>
<name>linux</name>
<family>unix</family>
<arch>amd64</arch>
</os>
<property>
<name>!crossCompile</name>
</property>
</activation>
<properties>
<current-os>linux</current-os>
<current-arch>amd64</current-arch>
<build-target>native-build-linux-x86_64</build-target>
</properties>
</profile>
</profiles>
pom.xml source code here
Travis CI Log here
Looks like I need to explicitly deactivate the build-linux-amd64 profile. I compiled using
mvn clean compile -P'cross-compile,!build-linux-amd64'
and now it works as expected.
From what you provided in Travis log, I find you are running maven with
mvn --settings scripts/settings.xml install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V
In this step, you were compiling the code without profile option.
Then you run
mvn package -Pcross-compile -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true.
In this packing step, the code is compiled. So mvn will not use the compile options in the profile to compile the code again.
So try to add the profile option in the first mvn install command.
Related
I have 2 profiles in Maven's settings.xml but I cannot trigger them by the -P option, always the second is used:
<profiles>
<profile>
<id>wilfly-local</id>
<activeByDefault>true</activeByDefault>
<properties>
<wildfly-hostname>127.0.0.1</wildfly-hostname>
<wildfly-port>zzzz</wildfly-port>
<wildfly-username>xxx</wildfly-username>
<wildfly-password>S3cret</wildfly-password>
</properties>
</profile>
<profile>
<id>wildfly-remote</id>
<activeByDefault>false</activeByDefault>
<properties>
<wildfly-hostname>192.168.xxx.yyy</wildfly-hostname>
<wildfly-port>zzzz</wildfly-port>
<wildfly-username>xxx2</wildfly-username>
<wildfly-password>S3cret</wildfly-password>
</properties>
</profile>
</profiles>
...
<activeProfiles>
<activeProfile>wildfly-local</activeProfile>
<activeProfile>wildfly-remote</activeProfile>
</activeProfiles>
My pom.xml:
...
<build>
<finalName>mvnweb</finalName>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.2.1.Final</version>
<configuration>
<hostname>${wildfly-hostname}</hostname>
<port>${wildfly-port}</port>
<username>${wildfly-username}</username>
<password>${wildfly-password}</password>
</configuration>
</plugin>
</plugins>
</build>
...
The problem is when I try mvn wildfly:deploy -P wildfly-local, Maven deploys the war file on the remote server.
When I change the order of profiles then the second one is used (I checked it with -X option when I ran it). Both profiles deploys the project properly.
The activeByDefault tag do nothing, if I comment it out the result remains the same.
Can somebody tell me what should I do to get -P trigger work properly?
Thanks in advance!
From documentation:
The final piece of the settings.xml puzzle is the activeProfiles element. This contains a set of activeProfile elements, which each have a value of a profile id. Any profile id defined as an activeProfile will be active, reguardless of any environment settings. If no matching profile is found nothing will happen. For example, if env-test is an activeProfile, a profile in a pom.xml (or profile.xml with a corrosponding id will be active. If no such profile is found then execution will continue as normal.
Since you have both your profiles specified in your settings.xml they are activated both. Second one probably overwrites properties.
You should remove your activeProfiles from settings.xml if you want enable then only by -P CLI argument
<activeProfiles>
<activeProfile>wildfly-local</activeProfile>
<activeProfile>wildfly-remote</activeProfile>
</activeProfiles>
I have a JUnit 4.12 SlowTests test suite that I want to exclude from execution unless specifically requested on the Maven command line.
I have added the following to my pom file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<excludedGroups>com.Example.SlowTests</excludedGroups>
<includes>
<include>**/*TestSuite.class</include>
</includes>
<excludes>
<exclude></exclude>
</excludes>
</configuration>
</plugin>
I have defined the category as SlowTests and applied it to the MySlowTests class.
I have annotated the test suite as follows:
#RunWith(Categories.class)
#IncludeCategory(SlowTests.class)
#SuiteClasses({ MySlowTests.class })
public class MySlowTestSuite
When I run mvn package all the unit tests except MySlowTests are executed.
However, looking at various answers such as https://stackoverflow.com/a/25639372/820657 and https://stackoverflow.com/a/21830866/820657 I expected the following command:
mvn package -Dgroups=com.Example.MySlowTests
to run the excluded MySlowTests tests but they don't run. In fact no tests run.
What am I doing wrong?
The Maven Surefire plugin has some issues w.r.t categories in versions < 2.13 (IIRC) but as long as you are using Surefire >= 2.13 the following will run any classes annotated with #Category(com.yourcompany.SlowTests.class):
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>com.yourcompany.SlowTests</groups>
</configuration>
</plugin>
This approach is often used with profiles, the following configuration ...
<profiles>
<profile>
<id>slow</id>
<properties>
<testCategories>com.yourcompany.SlowTests</testCategories>
</properties>
</profile>
<profile>
<id>fast</id>
<properties>
<testCategories>com.yourcompany.FastTests</testCategories>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>${testCategories}</groups>
</configuration>
</plugin>
</plugins>
</build>
... can be used to run:
mvn install -P slow: runs the slow tests only
mvn install -P fast: runs the fast tests only
mvn install -P fast,slow: runs the fast and slow tests
Update 1: for this question: "Is there a way to use this approach so I can run all fast tests by default?"
You can define two properties:
<properties>
<includedCategories></includedCategories>
<excludedCategories>com.yourcompany.SlowTests</excludedCategories>
</properties>
Then update your surefire plugin definition like so:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<groups>${includedCategories}</groups>
<excludedGroups>${excludedCategories}</excludedGroups>
</configuration>
</plugin>
And, finally, add this profile:
<profile>
<id>slow</id>
<properties>
<includedCategories>com.yourcompany.SlowTests</includedCategories>
<excludedCategories></excludedCategories>
</properties>
</profile>
This just toggles the includedCategories and excludedCategories properties. By default, you include everything except those tests annotated with com.yourcompany.SlowTests (i.e. everything except your 'slow' tests). When you run with -P slow you exclude everything except those tests annotated with com.yourcompany.SlowTests (i.e. everything except your 'slow' tests).
Note: what I said in my original answer about Surefire versions < 2.13 misbehaving with Categories still stands so to make this work you need to be using a version of the Maven Surefire plugin >= 2.13.
I am trying to specify, in my maven settings.xml and my pom.xml, which jvm to use for my gwt project.
I am using the suggestion from https://stackoverflow.com/a/20787334/265119. I have used this on other, non-gwt projects successfully.
Now however it seems that maven is ignoring this, and continues to use java 8, whereas I have set the following in my settings.xml:
<profiles>
<profile>
<id>default</id>
<properties>
<JAVA_1_7_HOME>/usr/lib/jvm/java-7-oracle/bin/javac</JAVA_1_7_HOME>
<JAVA_1_8_HOME>/usr/lib/jvm/java-8-oracle/bin/javac</JAVA_1_8_HOME>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
And in my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<executable>${JAVA_1_7_HOME}</executable>
</configuration>
</plugin>
Does anyone know why maven is ignoring these?
Does the gwt maven plugin also need to specify the jvm version?
Thanks
Is the profile really activated? Your POM ought to work, but only if the profile is activated.
You can run mvn help:active-profiles to find out if your profile is active.
Also, in order for <executable> to work, you need to set <fork>true</fork> as well. As explained here: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#executable
When using the maven release plugin, both mvn release:prepare and mvn release:perform will run the tests.
Is there any way I can configure things so they only run during mvn release:prepare?
I know you can pass:
-Darguments="-DskipTests"
But this will skip the tests during both goals, which I don't want. And I also don't want them to run during just mvn release:perform and not prepare, as a failure during perform will have already tagged the repository.
You should be able to do that by adding the <releaseProfiles> element to the release-plugin configuration. This will only be used for release:perform Mojo.
Something like this should do the trick:
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<releaseProfiles>skipTestsForReleasePerform</releaseProfiles>
</configuration>
</plugin>
</plugins>
</build>
(...)
<profiles>
<profile>
<id>skipTestsForReleasePerform</id>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
</profiles>
When using Tycho to build a project, the test cases are run in a new process using the equinox launcher to run -application org.eclipse.tycho.surefire.osgibooter.headlesstest.
How can I debug the test cases?
There is a much easier way to accomplish this:
just add -DdebugPort=8000 to your Maven commandline and attach a remote debug session.
See the docs https://www.eclipse.org/tycho/sitedocs/tycho-surefire-plugin/test-mojo.html#debugPort
Add this to your POM:
<profiles>
<profile>
<id>debug</id>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<argLine>-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Now you can enable debugging with mvn ... -P debug when the following line is printed:
Listening for transport dt_socket at address: 8000
See the Eclipse help how to configure the IDE.