如何通过Maven只复制操作系统特定的依赖性jar



我目前正在开发一个使用nd4j、deeplearning4j依赖项的项目。这些依赖项包括不同操作系统的版本,如"nd4j-native-1.00-beta6-android-arm.jar"或"nd4j-native-1.00-beta6-linux-armhf.jar"等。

由于该项目将只在linux-x64上运行,我想知道是否有办法告诉Maven不要复制不需要的JAR。我希望减少不必要的libs所需的磁盘空间。

pom.xml目前看起来是这样的,可以生成一个可部署的输出:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyGroup</groupId>
<artifactId>MyApp</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.clerezza.ext</groupId>
<artifactId>org.json.simple</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
<artifactId>junixsocket-core</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.kohlschutter.junixsocket</groupId>
<artifactId>junixsocket-server</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>1.0.0-beta6</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>1.0.0-beta6</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-parallel-wrapper</artifactId>
<version>1.0.0-beta6</version>
</dependency>
</dependencies>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathLayoutType>repository</classpathLayoutType>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>MyMainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

通常,如果您想为dl4j或任何基于javacpp的东西捆绑特定于平台的二进制文件,可以执行以下操作:https://github.com/bytedeco/javacpp-presets/wiki/Reducing-the-Number-of-Dependencies

具体来说,您只需为所有javacpp依赖项指定-Djavacpp.platform=linux-x86_64。

您可以在依赖项上设置<exclusions>

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

例如:

<dependency>
<groupId>com.something</groupId>
<artifactId>some-jar</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>  
<groupId>de.dumm</groupId>
<artifactId>nicht-benutzen</artifactId>
</exclusion>
</exclusions> 
</dependency>

相关内容

  • 没有找到相关文章

最新更新