从 OS 系列中选择 maven 配置文件

Ken*_*ams 6 operating-system pom.xml maven maven-profiles

我想根据操作系统类型设置一些属性,所以我在我的 pom.xml

<project ...>
    <profiles>
        <profile>
            <id>KenMacbook</id>
            <activation>
                <os><family>mac</family></os>
            </activation>
            <properties>
                <test.r.version>3.3</test.r.version>
            </properties>
        </profile>
        <profile>
            <id>LinuxBox</id>
            <activation>
                <os><family>unix</family></os>
            </activation>
            <properties>
                <test.r.version>3.2</test.r.version>
            </properties>
        </profile>
    </profiles>
    ...
</project>
Run Code Online (Sandbox Code Playgroud)

在我的 Mac 上,我检查哪些配置文件处于活动状态:

% mvn help:active-profiles | grep -v INFO
Active Profiles for Project 'com.foo:bar:jar:2.0.3-SNAPSHOT': 

The following profiles are active:

 - nexus (source: external)
 - KenMacbook (source: com.foo:bar:2.0.3-SNAPSHOT)
 - LinuxBox (source: com.foo:bar:2.0.3-SNAPSHOT)
Run Code Online (Sandbox Code Playgroud)

所以它看起来像 <activation>LinuxBox轮廓没有成功排除在Mac上该配置文件。我对配置文件选择的工作方式有误解吗?

马文详情:

% mvn --version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T10:41:47-06:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.5", arch: "x86_64", family: "mac"
Run Code Online (Sandbox Code Playgroud)

Leo*_*sev 8

正确的解决方案是指定名称。

<activation> 
            <os> 
                <family>unix</family> 
                <name>Linux</name>
            </os> 
</activation>  
Run Code Online (Sandbox Code Playgroud)

一个完整的跨平台解决方案是:

<profile>
  <id>mac</id>
  <activation>
    <os> 
      <family>mac</family>
    </os>
  </activation>
      <modules>
        <module>tests/org.eclipse.swt.tests.cocoa</module>
      </modules>
</profile>
<profile>
  <id>unix</id>
  <activation>
    <os>
      <family>unix</family>
      <name>Linux</name>
    </os>
  </activation>
      <modules>
        <module>tests/org.eclipse.swt.tests.gtk</module>
      </modules>
</profile>
<profile>
  <id>windows</id>
  <activation>
    <os>
      <family>windows</family>
    </os>
  </activation>
      <modules>
        <module>tests/org.eclipse.swt.tests.win32</module>
      </modules>
</profile>
Run Code Online (Sandbox Code Playgroud)

来源:http : //maven.40175.n5.nabble.com/Profile-activation-for-mac-and-linux-td3263043.html