I am encountering a weird issue.
I have two spring-boot projects built using maven. They are named customers and rest-client.
They are based on spring-boot 3.2.2 and use Maven as the build tool.
Maven version on my machine:
mvn -v
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Java version:
java 21 2023-09-19
Java(TM) SE Runtime Environment Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)
The rest-client project is dependent on the customers project as it uses a DTO (Java record).
I have added the dependency in the rest-client pom.xml as below
<dependency>
<groupId>com.adityasamant.learnings</groupId>
<artifactId>customers</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
The jar is present in the local Maven repository as seen below:
/Users/adityasamant/.m2/repository/com/adityasamant/learnings/customers/2.0.0-SNAPSHOT
adityasamant@Adityas-MacBook-Pro 2.0.0-SNAPSHOT % ls
_remote.repositories customers-2.0.0-SNAPSHOT.jar customers-2.0.0-SNAPSHOT.pom maven-metadata-local.xml
I have pointed to the local maven repository using the below field in my settings.xml
<localRepository>/Users/adityasamant/.m2/repository</localRepository>
The dependencies seem to get resolved in IntelliJ IDEA.
But when I build the rest-client project using mvn clean install, maven is not able to resolve packages from the customers module and throws exceptions in compilation.
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project rest-client: Compilation failure: Compilation failure:
[ERROR] /Users/adityasamant/Documents/work/code/spring/rest-client/src/main/java/com/adityasamant/learnings/restclient/controller/RestClientController.java:[3,50] package com.adityasamant.learnings.customers.model does not exist
Any help would be greatly appreciated.
I have tried the following:
I have pointed to the local maven repository using the below field in my settings.xml
<localRepository>/Users/adityasamant/.m2/repository</localRepository>I have also tried to rename the _remote.repositories file under
/Users/adityasamant/.m2/repository/com/adityasamant/learnings/customers/2.0.0-SNAPSHOT
This did not help.
As the dependencies get resolved in IntelliJ IDEA, I was expecting that the Maven build would pass seamlessly as well.
You could try something like this: in your
pom.xmladd this repository as child of yourrepositoriestag:In the directory where you have your pom file (that is the project.basedir for maven), create a dir named
maven_repoand inside it place your directories so that you will form the pathmaven_repo/com/adityasamant/learnings/customers/2.0.0-SNAPSHOT(and in the last folder of your path you will place your jar of course)