1

I have a maven project with multiple submodules.

I have a root pom file in which I have the jackson dependency

<dependency>
 <groupId>fasterxml.jackson.core</groupId>
 <artifactId>jackson-databind</artifactId>
 <version>${jackson.version}</version>
</dependency>

I have the jackson dependency in one module called 'api'.

<dependency>
 <groupId>fasterxml.jackson.core</groupId>
 <artifactId>jackson-databind</artifactId>
 <scope>provided</scope>
</dependency>

I have a new module named 'client' in which I import the maven dependency of 'api'

<dependency>
 <groupId>abc.com</group>
 <artifactId>api</artifactId> 
 <version>0.1.0-SNAPSHOT</version>
 <scope>provided</scope>
</dependency>

I am using the following command to compile.

mvn -Djackson.version=2.4.4 compile

I am getting a compile error if I try to import jackson libraries to the client module unless I add the jackson dependency explicitly again to the client module

Why is adding the api dependency not sufficient as it already contains the jackson dependency

1 Answer 1

2

You define the jackson dependency in api as provided, so it is not transitive:

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.

- https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope (emphasis added)

Sign up to request clarification or add additional context in comments.

3 Comments

sorry. I have updated the question. I'm passing the version when I try to compile
It's not the version missing, it's that the api's dependency on jackson is declared as <scope>provided</scope>. Where are you using the root pom? Only api or client as well?
I am using the root pom for both api and client. And passing the jackson.version when i compile. Isn't tat sufficient ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.