How to activate a pom.xml iff the os is not of a given family (eg. mac)?

1.5k views Asked by At

From Maven's website:

    ...
  <profiles>
    <profile>
      <id>default-tools.jar</id>
      <activation>
        <property>
          <name>java.vendor</name>
          <value>Sun Microsystems Inc.</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
          <version>1.4.2</version>
          <scope>system</scope>
          <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
  ...

tools.jar is already inclduded on Macs, embedded with classes.jar. Was there no way to specify !mac in the activation settings (except for listing every os except the mac) in the pom.xml, instead of always getting:

ERROR>warning: [path] bad path element ""/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/lib/tools.jar"": no such file or directory
2

There are 2 answers

2
Can't Tell On

I found another method. Have the dependency in an "activeByDefault" profile. Have another profile (profile-2) which gets activated if the OS is mac. According to this the "activeByDefault" profiles get deactivated if any of the other profiles get activated. So if the OS is mac, profile-2 will get activated, which will deactivate the "activeByDefault" profile.

0
prunge On

You can use the '!' modifier in the os section of activation (tried and works with Maven 3.0.3). Uses the same algorithm as the enforcer plugin, described here.

<profiles>
    <profile>
        <id>not-mac</id>
        <activation>
            <os>
                <family>!mac</family>
            </os>
        </activation>
        <properties>
            <!-- Define non-mac properties here -->
        </properties>
    </profile>
</profiles>

See this article for a more complete description of using tools.jar in Maven.