Maven profile not deploying to correct tomcat using maven-tomcat-plugin - maven

So my Maven doesn't want to pickup the right profile, doesn't matter how I tell it:
mvn -Denv=dev tomcat7:deploy-only or mvn -P dev -Denv=dev tomcat7:deploy-only
I have two servers configured on my settings.xml and have my configuration below pointing to the correct ones.
Using mvn -X it seems that Maven is always picking up the last server in order it appears on the file, which means it's picking up the prod server.
Any clues anyone? Thank you!
Here's my <profiles>:
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>dev</server>
<url>http://localhost:8080/manager/text</url>
<username>tomcat</username>
<password>tomcat</password>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>prod</id>
<activation>
<property>
<name>env</name>
<value>prod</value>
</property>
<jdk>1.6</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>prod</server>
<url>http://remote/manager/text</url>
<username>usr</username>
<password>pwd</password>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

You have an extra "activation" of <jdk>1.6</jdk> in your prod profile. Activations are an "or", not an "and". I'm guessing you're running maven with jdk6, and so prod is always active. Being the last one in the pom, its settings will win--a general rule in maven.

Related

<activeByDefault/> doesn't work when another profile triggered

I have profiles look like this.
<profile>
<id>active-by-default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>${version.org.mongodb}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>java8</id>
<activation>
<jdk>(,1.8]</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>java9</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<libs>
<lib>${java.home}/jmods/java.base.jmod</lib>
</libs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Those two java- profiles are for ProGuard.
And I found the active-by-default profile doesn't work even with no profiles specified.
I found it works when I remove one of those java- profile which meets my current JDK version.
Is this intended?
Yes, this is the documented behaviour :
This profile will automatically be active for all builds unless another profile in the same POM is activated using one of the previously described methods. All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config.
https://maven.apache.org/guides/introduction/introduction-to-profiles.html

Maven Plugin Surefire no accepting outputDirectory

In Maven pom tried to have a single profile only for tests and their reports. Also all test related reports should end up in a single folder per project.
Acording to the documentation this should do the trick
<profiles>
<profile>
<id>integration</id>
<activation>
<property>
<name>integration</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/*$*</exclude>
<exclude>**/*_closure*</exclude>
<exclude>**/support/**</exclude>
</excludes>
<outputDirectory>${basedir}/target/reports</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Still all reports end up in ..\target\surefire-reports. Any idea why the ouputDirectory settings doesn't work
According to the documentation you have to use the reportsDirectory instead of outputDirectory which does not exist.

Skip exec-maven-plugin from Command Line Argument in Maven

By default in my project POM, exec-maven-plugin, rpm-maven-plugin will be executed,
which is not required in local compilation/build.
I want to skip these plugin execution by passing Command Line Arguments
I tried below command to skip them like normal plugins, but didn't work though!
mvn install -Dmaven.test.skip=true -Dmaven.exec.skip=true
-Dmaven.rpm.skip=true
This page should tell you that the name of the argument to be passed by cmdline (i.e. the user property) is called skip, which is a poorly chosen name. To fix this do the following:
<properties>
<maven.exec.skip>false</maven.exec.skip> <!-- default -->
</properties>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<skip>${maven.exec.skip}</skip>
</configuration>
</plugin>
Try -Dexec.skip from specification:
http://www.mojohaus.org/exec-maven-plugin/java-mojo.html#skip
Using profiles (as little as possible) and execution phase you may achieve what you want for plugins that do not handle the skip property:
Plugin configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<executions>
<execution>
<phase>${rpmPackagePhase}</phase>
<id>generate-rpm</id>
<goals>
<goal>rpm</goal>
</goals>
</execution>
</executions>
<configuration>
...
</configuration>
</plugin>
Profile configuration:
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<rpmPackagePhase>none</rpmPackagePhase>
</properties>
</profile>
<profile>
<id>rpmPackage</id>
<activation>
<property>
<name>rpm.package</name>
<value>true</value>
</property>
</activation>
<properties>
<rpmPackagePhase>package</rpmPackagePhase>
</properties>
</profile>
</profiles>
Invocation:
mvn package -Drpm.package=true [...]

Heroku: managing different properties files in with maven

Maybe someone can help me. I have searched the web but haven't been able to find a solution yet.
I have a java application running on Heroku. I want to be able to have different properties files loaded for different Heroku instances (dev, test, prod), but I get java.io.FileNotFoundException. This is what I have in my pom.xml.
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>env.APP_ENVIRONMENT</name>
<value>dev</value>
</property>
</activation>
<properties>
<profile.name>dev</profile.name>
</properties>
</profile>
<profile>
<id>test</id>
<activation>
<property>
<name>env.APP_ENVIRONMENT</name>
<value>test</value>
</property>
</activation>
<properties>
<profile.name>test</profile.name>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<property>
<name>env.APP_ENVIRONMENT</name>
<value>prod</value>
</property>
</activation>
<properties>
<profile.name>prod</profile.name>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>7.0.34.0</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/profiles/${profile.name}</directory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</resource>
</resources>
</build>
How to customize the Maven build is described here:
https://devcenter.heroku.com/articles/using-a-custom-maven-settings-xml
You can create a settings file for each build type:
settings.xml <-- Default
settings-dev.xml
settings-test.xml
settings-prod.xml
A production build could then be performed as follows:
heroku config:set MAVEN_SETTINGS_PATH=settings-prod.xml
git push heroku master
Details
The Java buildpack supports a way to specify a custom Maven settings file.
By default it uses a settings file located in the build directory, this can be overridden by setting one of the following variables:
MAVEN_SETTINGS_PATH
MAVEN_SETTINGS_URL

How to run the exec-maven-plugin if a system property id set in Maven 3.x?

I want to run the 'exec-maven-plugin' if a system property is set. How do I accomplish this in Maven 3.x?
For example, given:
mvn clean install -DrunTheExec="yes"
Then how can I implement this logic:
<!-- if $(runTheExec) == yes then run this plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
...
</plugin>
I was just about to add the same suggestion as Johnathon, but using the profile a little differently.
<profiles>
<profile>
<id>runTheExec</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
...
then to activate it:
mvn clean install -PrunTheExec
You'll need to define a profile in your pom, with the plugin defined inside of it. In your example, this would be:
<profiles>
<profile>
<activation>
<property>
<name>runTheExec</name>
<value>yes</value>
</property>
</activation>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
...
</plugin>
</plugins>
</profile>
</profiles>

Resources