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

后端 未结 2 1213
死守一世寂寞
死守一世寂寞 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: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

    
            org.nd4j
            nd4j-native-platform
            1.0.0-beta
        
    
        org.deeplearning4j
        deeplearning4j-core
        1.0.0-beta
    
    

    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

提交回复
热议问题