javamavenjarwarnd4j

Excluding certain .jars from a Maven dependency from build by classifier


My project includes the nd4j-native-platform dependency, which includes .jars for windows, linux, and mac. The app is developed on windows/mac machines then deployed to Linux, so I'd like to save space on deployment by excluding these other platform jars that take up > 400 MB when the .war is built. Tl;dr, I want to exclude all the .jars that don't end with linux-x86_64.

Dependency in pom:

<dependency>
    <groupId>org.nd4j</groupId>
    <artifactId>nd4j-native-platform</artifactId>
    <version>1.0.0-beta7</version>
    <classifier>linux-x86_64</classifier>
</dependency>

I don't see any way to exclude them by classifier in the dependency tag, it seems you can only exclude by groupId and artifactId. I also tried using packagingExcludes and warSourceExcludes in the .war plugin, but that didn't do anything:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.3</version>
    <configuration>
        <packagingExcludes>
            WEB-INF/lib/nd4j-native-1.0.0-beta7-windows-x86_64.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-android-x86.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-macosx-x86_64.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-android-x86_64.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-linux-ppc64le.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-android-arm64.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-android-arm.jar,
            WEB-INF/lib/openblas-0.3.9-1-1.5.3-windows-x86_64.jar,
            WEB-INF/lib/nd4j-native-1.0.0-beta7-linux-armhf.jar,
            WEB-INF/lib/openblas-0.3.9-1-1.5.3-windows-x86.jar,
            WEB-INF/lib/openblas-0.3.9-1-1.5.3-windows-x86.jar,
            WEB-INF/lib/openblas-0.3.9-1-1.5.3-linux-armhf.jar,
            WEB-INF/lib/openblas-0.3.9-1-1.5.3-linux-ppc64le.jar,
            WEB-INF/lib/openblas-0.3.9-1-1.5.3-linux-arm64.jar
        </packagingExcludes>
    </configuration>
</plugin>

Using Maven 3.6.3.


Solution

  • The correct way to deal with this for most things that use JavaCPP is to set the javacpp.platform property.

    When building with mvn -Djavacpp.platform=linux-x86_64 you will get only that specific platform and nothing else. This will also apply to all other transitive dependencies, e.g. opencv.

    You can try running mvn -Djavacpp.platform=linux-x86_64 dependency:tree to see that it works.