maven依赖中的scope使用

例如:

<dependencies>
    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <scope>compile</scope>
    </dependency>
</dependencies>

这里面有<scope>...</scope>,中间可以是下面的五个值,具体作用如下:

  • compile,缺省值,适用于所有阶段,会随着项目一起发布。
  • provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
  • runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
  • test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
  • system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。

一般常用的是compile和test。

猜你喜欢

转载自blog.csdn.net/HaigLee/article/details/69666513