how to create a local dependency with spring boot. I'm trying to create an application with a local dependency. I create the local dependency then import it into another spring boot project but it fails to import the local dependency classes into the other project.
This is the pom.xml of my local dependency:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>generateproto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>generate-proto</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.23.2</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.16.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.16.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.55.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.16.1</version>
</dependency>
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repositorio.local</id>
<name>Meu repositorio Local</name>
<url>file:../maven-repositorio</url>
</repository>
</repositories>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}
</pluginArtifact>
<clearOutputDirectory>false</clearOutputDirectory>
<outputDirectory>src/main/java</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The command to create my local directory:
mvn install:install-file -Dfile=target/generateproto-0.0.1-SNAPSHOT.jar -DgroupId=com.example -DartifactId=generateproto -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -DlocalRepositoryPath=../maven-repositorio
My other pom.xml project:
<dependency>
<groupId>com.example</groupId>
<artifactId>generateproto</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
The folder structure looks like this:
- -- another project ---local dependency ---maven-repositorio
But this framework fails to import the classes when I run the command:
mvn dependency:purge-local-repository
gives me the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.5.0:purge-local-repository (default-cli) on project cart-purchase-command: Failed to refresh project dependencies for: com.example:cart-purchase-command:jar:0.0.1-SNAPSHOT: required artifacts missing: [ERROR] com.example:generateproto:jar:0.0.1-SNAPSHOT
Does anyone know where I'm going wrong?
Thank you!