简体   繁体   中英

maven scope test with selenium

What is the difference when we use scope as test for some dependency in pom.xml file for a selenium project. Example : Difference between

<dependency>
 <groupId>org.seleniumhq.selenium</groupId>
 <artifactId>selenium-java</artifactId>
 <version>3.141.59</version>
 <scope>test</scope>
</dependency>

AND

<dependency>
 <groupId>org.seleniumhq.selenium</groupId>
 <artifactId>selenium-java</artifactId>
 <version>3.141.59</version>
</dependency>

The default scope is compile .

This scope adds the dependency to the project at compile-time and will also be exported when you create a JAR with dependencies (or similar)

The test scope adds the dependency just for test sources(eg Unit tests/located in src/test in most cases). It can only be accessed from test sources and will not be export(except to a test JAR)

If you only need selenium in the test code of the project, I recommand using the test scope.

Dependency Scope in Maven

The Dependency scope is used to limit the transitivity of a dependency which also effects the classpath used for various build related tasks.

Currently the following 6 dependency scope are supported by :

  • compile : compile scope is the default scope which is used if none is specified. Compile dependencies are available in all classpaths of a project. These dependencies are propagated to dependent projects.

    • Exmaple:

       <scope>compile</scope>
  • provided : provided scope is almost similar to compile but indicates you expect the JDK or a container to provide the dependency at runtime.

    • Exmaple:

       <scope>provided</scope>
  • runtime : runtime scope indicates that the dependency is not required at compile time but only for execution. It is in the runtime and test classpaths, but not the compile classpath.

    • Exmaple:

       <scope>runtime</scope>
  • test : test scope indicates that the dependency is not required for normal use of the application and is only available for the test compilation and execution phases. This scope is not transitive.

    • Exmaple:

       <scope>test</scope>
  • system : system scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

    • Exmaple:

       <scope>system</scope>
  • import : import scope is only supported on a dependency of type pom in the <dependencyManagement> section. It indicates the dependency to be replaced with the effective list of dependencies in the specified POM's section.

    • Exmaple:

       <scope>import</scope>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM