【问题标题】:Maven pom.xml argument that will install different dependencies depending on the value [duplicate]Maven pom.xml 参数将根据值安装不同的依赖项[重复]
【发布时间】:2019-12-15 05:34:22
【问题描述】:

我想在 Maven 上有一个属性/参数,它将根据参数安装不同的依赖项。

即当用户指定-DgpuCuda=True时,对pom.xml的依赖会相应改变。

所以mvn -gpuCuda=True install 将安装 DL4J-GPU 而不是 DL4J-CPU。

如果指定了 -gpuCuda=True,则将安装它:

<dependency>
 <groupId>org.nd4j</groupId>
 <artifactId>nd4j-cuda-10.1</artifactId>
 <version>1.0.0-beta4</version>
</dependency>

如果 -gpuCuda=False,则会安装:

<dependency>
 <groupId>org.nd4j</groupId>
 <artifactId>nd4j-native</artifactId>
 <version>1.0.0-beta4</version>
</dependency>

这可能吗?解决方法是什么? 谢谢!!

【问题讨论】:

标签: java maven build


【解决方案1】:

你添加类似的东西

 <profiles>

    <profile>
      <id>gpu</id>
      <activation>
        <property>
          <name>gpuCuda</name>
          <value>True</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.nd4j</groupId>
          <artifactId>nd4j-cuda-10.1</artifactId>
          <version>1.0.0-beta4</version>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>cpu</id>
      <activation>
        <property>
          <name>gpuCuda</name>
          <value>False</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
           <groupId>org.nd4j</groupId>
           <artifactId>nd4j-native</artifactId>
           <version>1.0.0-beta4</version>
        </dependency>
      </dependencies>
    </profile>
</profiles

然后您通过您声明的命令行属性激活/停用配置文件,例如mvn -DgpuCuda=True install

【讨论】:

  • 谢谢!做到了这一点!如果用户没有定义任何东西,有没有办法将 DgpuCuda=False 设置为默认值
  • 您可以将值从False 更改为!True
猜你喜欢
  • 2021-11-16
  • 2014-02-19
  • 1970-01-01
  • 1970-01-01
  • 2014-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
相关资源
最近更新 更多