0

I am trying to run a mvn clean install on a maven project that uses a local library.

Here is the pom.xml of the project I try to build :

<?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>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>cards</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cards</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</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-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.example</groupId>
            <artifactId>lib</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

I am trying to use my own library that is named lib.

When i use it on my project there is no problem on Eclipes, i can use the classes that are in my lib but when i run a mvn build it tells me package com.example.lib does not exist

Why is my library available in my Eclipes project but not when i build with maven?

1 Answers1

0

You need to install your lib into local cache to achieve the same:

mvn install:install-file -Dfile=lib.jar -DgroupId=com.example -DartifactId=lib -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar

Note that the M2Eclipse documentation states the difference:

  • Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository
F.I.V
  • 317
  • 1
  • 14
  • I think the question is asking about a locally cached library, not trying to download something from Maven Central – OneCricketeer Jun 10 '21 at 23:09
  • I did this but it still doesnt work and tells me the same error. Failed to execute goal on project cards: Could not resolve dependencies for project com.example:cards:jar:0.0.1-SNAPSHOT: Could not find artifact com.example:lib:jar:0.0.1-SNAPSHOT –  Jun 11 '21 at 12:07
  • @Axel: You mentioned various mvn goals such as build, clean and install. Please confirm your mvn goals are the same when you issue the command by comparing it with what eclipse shows before the "build successful" message. Maybe from eclipse you invoke "mvn repackage" while from command line you invoke "mvn build" or "mvn clean install"? Also does "mvn compile" produce the error as well? – F.I.V Jun 11 '21 at 19:45