如何在Gradle中使用分类器(平台版本)排除依赖项? [英] How to exclude dependency with classifier (platform version) in Gradle?

查看:445
本文介绍了如何在Gradle中使用分类器(平台版本)排除依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我依赖于'org.nd4j:nd4j-native-platform:0.6.0',这给我带来了传递性依赖:

In my project I have dependency on 'org.nd4j:nd4j-native-platform:0.6.0' which brings me transitive dependencies:

  • 等级:org.nd4j:nd4j-native:linux-ppc64le:0.6.0
  • 等级:org.nd4j:nd4j-native:macosx-x86_64:0.6.0
  • 等级:org.nd4j:nd4j-native:windows-x86_64:0.6.0
  • 等级:org.nd4j:nd4j-native:linux-x86_64:0.6.0

我想排除nd4j-native:linux-ppc64le和nd4j-native:macosx-x86_64,因为我的应用程序不支持这些平台.我写了我的Gradle文件:

I want to exclude nd4j-native:linux-ppc64le and nd4j-native:macosx-x86_64 since my application does not support these platforms. I write in my Gradle file:

configurations {
    all.collect { configuration ->
        configuration.exclude(group: 'org.nd4j', module: 'nd4j-native', classifier: 'linux-ppc64le')
    }
}

Gradle说:

错误:(44,0)无法为org.gradle.api.internal.artifacts.DefaultExcludeRule类型的对象设置未知属性分类器".

Error:(44, 0) Could not set unknown property 'classifier' for object of type org.gradle.api.internal.artifacts.DefaultExcludeRule.

似乎gradle不支持分类器的排除.

It seems that gradle does not support exclusion by classifier.

如何排除这种传递依赖?

How to exclude such a transitive dependencies?

更新:Gradle允许我们排除依赖项,但是如果我们有多个具有相同ID和组但分类器不同的依赖项,怎么办?

Update: Gradle allows us to exclude dependencies, but what if we have several dependencies with the same id and group but different classifiers?

推荐答案

我也遇到过同样的问题.我已经使用了具有Gradle依赖关系的deeplearning4j库.

I have faced the same issued. I have used a deeplearning4j library with Gradle dependency.

compile group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta'
compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta'

使用此工具时,它还会下载其他平台分类程序,其大小几乎为 500MB .但是我的用例特定于Windows平台,因此我不需要用于Linux和Android及其他平台的其他分类器.如果我排除该组,它也排除了Windows的分类器.据我所知,在Gradle中,我们不能排除特定的分类器.

When I use this it is also downloading other platform classifiers and its size is almost 500MB. but my use case is specific to the Windows platform so i don't need other classifiers for Linux and Android and other platforms.If I exclude the group it is also excluding the classifier for the windows also . And in Gradle as of my knowledge, we can not exclude specific classifiers.

所以问题是如何删除特定的分类器.我感到奇怪的是,当我制作项目的jar文件并提取jar时,它向我显示了org.nd4j:nd4j-native:linux-ppc64le:0.6.0和其他jar,但是当我生成依赖关系树时,却没有向我显示树中的特定jar.

So the question was how to remove the specific classifier. What I found strange is when I made jar file of the project and extracted jar it shows me the org.nd4j:nd4j-native:linux-ppc64le:0.6.0 and other jars but when I generate dependency tree it is not showing me the specific jar in the tree.

所以为了找出jar来自哪个特定模块和项目,我做了一个单独的maven项目,并以此

So in order to find out in which specific module and project the jar is coming from I made a separate maven project and with this

<dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-native-platform</artifactId>
        <version>1.0.0-beta</version>
    </dependency>
<dependency>
    <groupId>org.deeplearning4j</groupId>
    <artifactId>deeplearning4j-core</artifactId>
    <version>1.0.0-beta</version>
</dependency>

,然后我生成了一个依赖关系树.它向我展示了依赖树中的罐子. 我所做的是,我删除了整个模块,并在具有特定版本的特定模块中添加了所需的分类器,并且对我有用.

and then I have generated a dependency tree. It showed me the jars in the dependency tree. What I did is I have removed the whole module and I have added the required classifier in a particular module with a specific version and it worked for me.

compile (group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '1.0.0-beta') 
{
exclude group: 'org.bytedeco.javacpp-presets', module: 'opencv-platform'
exclude group: 'org.bytedeco.javacpp-presets', module: 'leptonica-platform'
exclude group: 'org.bytedeco.javacpp-presets', module: 'hdf5-platform'

}
compile (group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta')
{
    exclude group: 'org.bytedeco.javacpp-presets', module: 'openblas-platform'
}

compile group: 'org.nd4j', name: 'nd4j-native', version: '1.0.0-beta', classifier: "windows-x86_64"
compile group: 'org.bytedeco.javacpp-presets', name: 'openblas', version: '0.2.20-1.4.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'openblas', version: '0.2.20-1.4.1', classifier: "windows-x86"
compile group: 'org.bytedeco.javacpp-presets', name: 'openblas', version: '0.2.20-1.4.1', classifier: "windows-x86_64"
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.4.1-1.4.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.4.1-1.4.1',classifier: "windows-x86"
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.4.1-1.4.1',classifier: "windows-x86_64"
compile group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.75.3-1.4.1'
compile group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.75.3-1.4.1',classifier: "windows-x86"
compile group: 'org.bytedeco.javacpp-presets', name: 'leptonica', version: '1.75.3-1.4.1',classifier: "windows-x86_64"

这样做使我的jar大小减少到几乎 250MB

Doing this reduced my jar size to almost 250MB

这篇关于如何在Gradle中使用分类器(平台版本)排除依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆