Search code examples
javamavenjarhtmlunit

Maven dependencies size


I have faced with a little problem, I have added next dependency in my project:

<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.19</version>
</dependency>

And my project enlarges from 330kb to 12.1mb . I know that HTMLUnit based on Apache Http Client that weights much, but maybe Maven has some feature to exclude libraries/packages that doesn't used in sources? (not manual excluding)


Solution

  • How should Maven know that? You might using some kind of DI which is during runtime ? You can of course exclude dependencies if you know that they are not used...and of course handle the dependencies correct for their purpose as already mentioned to use <scop>test</scope> if it's something which is used only for testing.

    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>jar</packaging>
      ...
      <dependencies>
        <dependency>
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
          <version>1.0-SNAPSHOT</version>
          <exclusions>
            <exclusion>
              <groupId>sample.ProjectD</groupId>
              <artifactId>Project-D</artifactId>
            </exclusion>
          </exclusions>
        </dependency>
      </dependencies>
    </project>