Saturday, November 29, 2014

Maven: Scope of dependency

By default, all dependencies defined in the pom file of a Maven project has a scope of compile. In other words, maven will download source and compile and propagate them when building the maven project. There are several other scopes which i like to discuss here:

Scope: provided

By this scope, the compile classes in the dependency related to the Maven project (e.g. by the "import" statements in the project's java codes) will be included during the build and runtime execution

Scope: runtime

By this scope, the dependency's jar file will be included in the runtime classpath during the execution of the maven project.

To find what is included in the runtime path of a Maven project, navigate to the project's root folder and run the following command:

> mvn dependency:build-classpath

Scope: test

By this scope, the dependency will not be included during build or runtime, but will be included for unit testing.

No comments:

Post a Comment