How to exclude dependency with classifier (platform version) in Gradle?

后端 未结 2 1215
死守一世寂寞
死守一世寂寞 2021-02-13 03:38

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

  • Gradle: org.nd4j:nd4j-native:linux-ppc64le:0.6.
相关标签:
2条回答
  • 2021-02-13 04:16

    How to exclude such a transitive dependencies?

    I think, the only way is to exclude all transitive dependencies by it's module or group and manually provide dependencies on libraries for platforms your application supports. Because classifiers are supported in dependency declaration.

    And the same way you can handle the case, when you have a number of dependencies with the same module and grooup, but with different classifiers. Just add such dependencies manually with it's classifier property.

    0 讨论(0)
  • 2021-02-13 04:35

    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'
    

    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.

    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.

    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"
    

    Doing this reduced my jar size to almost 250MB

    0 讨论(0)
提交回复
热议问题