Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Maven not using the expected profile?

I am using Maven to build some projects and it's using the gMaven plugin to build an RPM that includes the main artifact. I only want Maven to attempt to build the RPM on systems that have rpmbuild, and not on systems that do not, so I built two separate profiles, one that is supposed to be default and one that is supposed to activate when on a Unix family OS.

I could have sworn that I tested it and everything worked correctly, but now it is running the Unix-family profile even when I build on OSX. However, if I change the profile's OS family to "windows" it definitely knows it is not on a Windows machine and therefore runs the default profile.

Here is the relevant section of my pom.xml file:

<profiles>
    <profile>
        <id>default-profile</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <rpmPhase>none</rpmPhase>
        </properties>
    </profile>
    <profile>
        <id>rpm-profile</id>
        <activation>
            <os>
                <family>unix</family>
            </os>
        </activation>
        <properties>
            <rpmPhase>package</rpmPhase>
        </properties>
    </profile>
</profiles>

In the Maven output:

OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac"

However, Maven is setting rpmPhase to "package," instead of "none," which is not the expected behavior.

Can anyone see if I'm missing something here?

EDIT:

Also, if I set the OS family to something that doesn't exist, or if I comment out the activation block altogether then the default profile is used, so it seems that Maven is actively matching my OSX with a Unix family OS.

like image 260
J Ellis Avatar asked Sep 15 '14 22:09

J Ellis


2 Answers

I had this same issue, heres a JIRA issue explaining the problem:

https://jira.codehaus.org/browse/MNG-4983

They say its actually not a bug. Here's a workaround if you need OSX and Unix to be separate:

<os>
  <family>unix</family>
  <name>!mac os x</name>
</os>
like image 88
Ring Avatar answered Sep 26 '22 12:09

Ring


So after looking around it appears that OSX matches "Unix family" under Maven. Apparently the check flags any OS ending in "x" as Unix family, which seems like a dumb way to do it. Unfortunately, it doesn't appear that you can do any AND or OR operators, so you have to choose one family, and one family only. Because of this, I changed unix to !mac to at least avoid the issue under OSX. It would, of course, still crop up if the build was running on Windows.

like image 35
J Ellis Avatar answered Sep 24 '22 12:09

J Ellis