I'm completely new to Maven. I'm trying to set up a new project such that it doesn't require 20 page long word docs with screenshots to set it up. I've got developers on Macs and PCs, so I need to be able to customize the catalina.home directory as I can't just impose a standard location. I thought I'd do it in the ~/.m2/settings.xml file with the following:
<profile>
<id>my-site-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<catalina.home>/path/to/apache-tomcat</catalina.home>
</properties>
</profile>
However, the documentation here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html#Profile_Pitfalls seems to indicate that what I'm trying to accomplish is a bad idea. What's the official way of accomplishing this so that in my pom.xml I can just reference ${catalina.home}?
And now that I've declared my profile with an id, can I fail the build if my pom.xml can't load the profile "my-site-dev"? I'd like to get that <activeByDefault> out of the settings.xml if at all possible. I don't want to interfere with their global settings for no reason, I'd like to keep as much of it self contained as possible.
Don't use activeByDefault, since it will cloak all other profiles:
Here is what you should use:
<profiles>
<profile>
<id>path-to-catalina.home-linux</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<properties>
<catalina.home>...</catalina.home>
</properties>
</profile>
<profile>
<id>path-to-catalina.home-mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<catalina.home>...</catalina.home>
</properties>
</profile>
<profile>
<id>path-to-catalina.home-windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<catalina.home>...</catalina.home>
</properties>
</profile>
You could use a profile in your pom that gets activated based on os.
<profiles>
<profile>
<activation>
<os>
...
What are you doing that require catalina.home?
If you're doing deployment to an app server with maven, you are already outside of the 'consistent, portable build' rule set - and outside of the main use case / best practices for maven.
Not that you shouldn't do it - as it's convenient. Just make sure to separate your build projects from the deployment projects.
Related
Trying to get a properties to be set based upon whether a user's OS is windows 10+ or below.
However whenever I enable the command inside the OS tags, the properties are not set. Comment them out however and then the properties are set again.
Code below:
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
<version>(,10.0)</version>
</os>
</activation>
<properties>
<ChromeWebDriverLocation>${basedir}${file.separator}driver${file.separator}win32${file.separator}chrome${file.separator}chromedriver.exe</ChromeWebDriverLocation>
<IEWebDriverLocation>${basedir}${file.separator}driver${file.separator}win32${file.separator}ie${file.separator}IEDriverServer.exe</IEWebDriverLocation>
<SkipIETests>false</SkipIETests>
<SkipEdgeTest>true</SkipEdgeTest>
</properties>
</profile>
<profile>
<id>windows10Edge</id>
<activation>
<os>
<family>windows</family>
<version>[10.0,)</version>
</os>
</activation>
<properties>
<ChromeWebDriverLocation>${basedir}${file.separator}driver${file.separator}win32${file.separator}chrome${file.separator}chromedriver.exe</ChromeWebDriverLocation>
<EdgeWebDriverLocation>${basedir}${file.separator}driver${file.separator}win64${file.separator}edge${file.separator}MicrosoftWebDriver.exe</EdgeWebDriverLocation>
<SkipIETests>true</SkipIETests>
<SkipEdgeTest>false</SkipEdgeTest>
</properties>
</profile>
<profiles>
I get the following after i pull the latest code from the githud repository.
problem encountered while building effective model for org.codehaus.mo
The full description of the error is below.
1 problem was encountered while building the effective model for
org.codehaus.mojo:aspectj-maven-plugin:1.8
[ERROR] 'dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${toolsjarSystemPath} #
I am using java1.8 and sts 3.6.4
Most likely JAVA_HOME environmental variable points to JDK instead of JRE. Change the environment variable and restart Eclipse.
aspectj-maven-plugin contains following:
<profile>
<id>standardToolsJar-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjarSystemPath>${java.home}/../lib/tools.jar</toolsjarSystemPath>
</properties>
</profile>
<profile>
<id>appleJdkToolsJar-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjarSystemPath>${java.home}/../Classes/classes.jar</toolsjarSystemPath>
</properties>
</profile>
<profile>
<id>java8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>
</profile>
I think the reason this fails is that activeByDefault will not trigger because java8 profile activation is triggered. file->exists condition will not trigger because of incorrect ${java.home}. ${toolsjarSystemPath} will not get set, and attempt to use it will cause the exception.
I would like to create two sets of Sonar reports from the same project. One would have everything covered and the other one would have some packages excluded.
Is this possible and if so, how to do such?
Edit: Setting exclusions is not a problem but having two reports is.
Create new profile in maven and add call sonar with new branch for each profile: mvn clean install -Pprofile1 sonar:sonar -Dsonar.branch=BRANCH1
<properties>
<sonar.branch>
DEFAULT_BRANCH
</sonar.branch>
</properties>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://localhost:9000
</sonar.host.url>
</properties>
</profile>
<profile>
<id>profile1</id>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://myserver:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
I have a configurable property line.ending that I used during the assembly phase of the building of my project to specify the line ending type of my application property files. For that I have created two profiles LF_DOS and LF_UNIX, so that when I launch :
mvn install
or
mvn install -P LF_DOS
line.ending equals 'dos', and when I launch :
mvn install -P LF_UNIX
line.ending equals 'unix'.
My first attempt to do this was simply :
<profile>
<id>LF_UNIX</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<line.ending>unix</line.ending>
</properties>
</profile>
<profile>
<id>LF_DOS</id>
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
<properties>
<line.ending>dos</line.ending>
</properties>
</profile>
Unfortunately, this always gave me line.ending=dos, whatever LF_UNIX is set or not. Weird... But, the more confusing to me, is that I solved the problem just by changing the profile declaration order, like this :
<profile>
<id>LF_DOS</id>
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
<properties>
<line.ending>dos</line.ending>
</properties>
</profile>
<profile>
<id>LF_UNIX</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<line.ending>unix</line.ending>
</properties>
</profile>
This works exactly like I want.
My questions is : is this a bug ? Or is it something to know about maven profiles, a kind of limitation that makes profiles order declaration particularly matter in such a case ?
The confusion lies in your understanding of how profile activation works.
You think that this:
<activation>
<property>
<name>!line.ending</name>
</property>
</activation>
means if I don't have a maven property named "line.ending" set, activate this profile. What it really means if I didn't specify -Dline.ending=X on the command line, activate this profile. So unless you run something like this:
mvn clean install -Dline.ending=unix
You are activating this profile and thus having the value set to dos.
I have two Maven profiles profile-A and profile-B. "B" should only be activated if "A" is not activated.
So if I would call
mvn install
profile-B is executed (but not profile-A).
But if I would call
mvn install -Pprofile-A
then only profile-A is executed (but not profile-B).
Any hints how I need to write my pom.xml to achieve this?
I already tried this, but it doesn't work:
<profiles>
<profile>
<id>profile-A</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
...
</profile>
<profile>
<id>profile-B</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!profile-A</name>
</property>
...
</activation>
...
</profile>
</profiles>
I think for your example command line to work as expected, all you need is the <activeByDefault>true</activeByDefault> for profile B.
http://maven.apache.org/guides/introduction/introduction-to-profiles.html states:
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.