The
"Transitive dependencies" feature allows you to avoid needing to
discover and specify the libraries that your own dependencies require,
and including them automatically.
The "dependency scope" is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks. There are 6 scopes available:
Pom of Project A
The "dependency scope" is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks. There are 6 scopes available:
- "compile" is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project.
- "provided" is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime.
- "runtime" 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" 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" 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" 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 <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.
Pom of Project A
<project>
...
<dependencies>
<dependency>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-app</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<project>
...
<dependencies>
<dependency>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-artifact-b</artifactId>
<version>1.0</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<project>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-artifact-b</artifactId>
<version>1.0</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-app</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Pom of Project A
<project>
...
<dependencies>
<dependency>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-artifact-b</artifactId>
<!-- This is not a jar dependency, so we must specify type. -->
<type>war</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
<project>
...
<dependencies>
<dependency>
<groupId>it.blogspot.informaticaamodomio</groupId>
<artifactId>my-artifact-b</artifactId>
<!-- This is not a jar dependency, so we must specify type. -->
<type>war</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
No comments:
Post a Comment