gpt4 book ai didi

maven-2 - 获取maven依赖的最佳方式

转载 作者:行者123 更新时间:2023-12-02 12:44:34 25 4
gpt4 key购买 nike

我只需要使用这个类org.apache.commons.io.FileUtils,但我正在下载所有我实际上不需要的commons类,有没有办法让maven只下载FileUtils类?不像下面的依赖项那样完全共享

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>

最佳答案

is there a way to say to maven download just FileUtils class?

没有。但根据您的具体用例,您可能可以使用 Maven Shade Plugin创建 uber-jar 并过滤包含的依赖项的内容:

Selecting Contents for Uber JAR

...

For fine-grained control of which classes from the selected dependencies are included, artifact filters can be used:

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.3.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>junit:junit</artifact>
<includes>
<include>junit/framework/**</include>
<include>org/junit/**</include>
</includes>
<excludes>
<exclude>org/junit/experimental/**</exclude>
<exclude>org/junit/runners/**</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

Here, Ant-like patterns are used to specify that from the dependency junit:junit only certain classes/resources should be included in the uber JAR. The second filter demonstrates the use of wildcards for the artifact identity which was introduced in plugin version 1.3. It excludes all signature related files from every artifact, regardless of its group or artifact id.

但请注意,FileUtils 依赖于其他类:

import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter; // depends on org.apache.commons.io.IOCase
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.output.NullOutputStream;

您显然也需要包含它。

关于maven-2 - 获取maven依赖的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3425119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com