Issue
I have a jar file which contains the following dependencies:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>tokens</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>tokens</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
</project>
I import this jar file into my other spring boot project hoping that I would not have to define these dependencies again but that is not the case, the jar file works fine on its own, same is the case with spring boot project if I add the dependencies then it is able to execute the classes in the jar file but what I don't get is why do I have to again define these dependencies?
Please help me with this, I have been stuck for a while now.
Solution
The junit-jupiter dependency has a test scope, so is not a transitive dependency. The rest of the dependencies are defaulted to compile scope and should therefore be transitive and you should not have to import them again. So you are missing something. Perhaps getting an older version, or not refreshed to the latest version.
I would find your local maven repo (usually in your user directory ./m2). And find the com/demo/tokens folder and delete it. Then re-install (mvn install) the dependency. If you are using an IDE such as eclipse, I would right click on the dependent project and choose Maven->update to force-update the dependency.
Answered By - crig