What is the difference between the maven scope compile
and provided
when artifact is built as a JAR? If it was WAR, I'd understand - the artifact would be included or not in WEB-INF/lib. But in case of a JAR it doesn't matter - dependencies aren't included. They have to be on classpath when their scope is compile
or provided
. I know that provided
dependencies aren't transitive - but is it only one difference?
相关问题
- Dependencies while implementing Mocking in Junit4
- Include pom.xml in Jar with gradle
- What order does maven find its dependencies?
- proguard causing EnumMap NPE on dynamically declar
- Maven: How to read the Parent POM version
相关文章
- IDEA2020 安装maven 插件后,springboot程序 SpringBootApplic
- pom文件中的插件定义
- pom.xml中的project为何报红
- Hibernate Tutorial - Where to put Mapping File?
- java.lang.NoClassDefFoundError: javax/servlet/http
- Cannot use org.jvnet.jax-ws-commons.jaxws-maven-pl
- New Maven install: mvn -version java.lang.ClassNot
- What's the difference between archetype.xml an
From the Maven Doc:
Recap:
Here is the reference.
Here is the brief on all supported dependencies ( source maven doc )
compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
runtime
This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
test
This 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.
system
This 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.
import (only available in Maven 2.0.9 or later)
This scope is only supported on a dependency of type pom in the section. It indicates the dependency to be replaced with the effective list of dependencies in the specified POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.
If you're planning to generate a single JAR file with all of its dependencies (the typical xxxx-all.jar), then provided scope matters, because the classes inside this scope won't be package in the resulting JAR.
See maven-assembly-plugin for more information
For a jar file, the difference is in the classpath listed in the MANIFEST.MF file included in the jar if addClassPath is set to true in the maven-jar-plugin configuration. 'compile' dependencies will appear in the manifest, 'provided' dependencies won't.
One of my pet peeves is that these two words should have the same tense. Either compiled and provided, or compile and provide.
Make available into class path, don't add this dependency into final jar if it is normal jar; but add this jar into jar if final jar is a single jar (for example, executable jar)
Dependency will be available at run time environment so don't add this dependency in any case; even not in single jar (i.e. executable jar etc)