Best way to get maven dependencies

I just need to use this org.apache.commons.io.FileUtils class, and yet I am loading all the public classes that I really don't need, is there any way to tell that maven only loads the FileUtils class? Not whole domains, as depending on the dependency below

<dependency>
   <groupId>commons-io</groupId>
   <artifactId>commons-io</artifactId>
   <version>1.4</version>
</dependency>
+3
source share
4 answers

is there any way to tell maven to download only the FileUtils class?

No. But depending on your specific use case, you can use Maven Shade Plugin to create uber-jar and filter the contents of included dependencies

Content Selection for Uber JAR

...

, :

<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>

Ant - , junit: junit / uber JAR. , 1.3 . , , .

, 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;

, , , .

+4

Apache commons io apache. io, . 100 , .

- !

FileUtils io. !

+1

<exclusion>

    <dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>

, .

mvn dependency:analyze-only mvn dependecy:tree, , , , / .

.

+1

. jar; ( ). , .

, - , FileUtils . , , . , . , FileUtils ( FileUtils .. ..). . , , , , maven .

0

Source: https://habr.com/ru/post/1758419/


All Articles