0

I have a project structure as follows:

enter image description here

I would like to put in common modules and classes visible to all microservices so I thought of adding common as a dependancy to microsevices but I get:

[INFO] gamification ....................................... SUCCESS [  4.178 s]
[INFO] multiplication ..................................... SUCCESS [  2.089 s]
[INFO] microservices ...................................... FAILURE [  0.069 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.694 s
[INFO] Finished at: 2022-12-01T23:52:34+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project microservices-parent: Could not resolve dependencies for project org.springframework.boot:microservices-parent:pom:0.0.1-SNAPSH
OT: Could not find artifact com.microservices.book:common-parent:jar:0.0.1-SNAPSHOT

After some diggin around I found that I can't link these two projects like that (so), and that I should probably use local repository... but I have no idea how. I don't even know how to save maven builds to the .m2 folder, I've tried:

 mvn -Dmaven.repo.local=C:\Users\pengwin\.m2\repository clean install

but I get:

[ERROR] No plugin found for prefix '.repo.local=C' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repos
itories [local (C:\Users\pengwin\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]

Here's microservices's pom.xml:

<?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.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <artifactId>microservices-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>microservices</name>
    <description>ms parent module</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <packaging>pom</packaging>

    <modules>
        <module>gamification</module>
        <module>multiplication</module>
    </modules>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
    </dependencies>



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

</project>

and here's common's pom.xml:

<?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.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.microservices.book</groupId>
    <artifactId>common-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>common</name>
    <description>common module</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <packaging>pom</packaging>

    <modules>
        <module>exceptions</module>
    </modules>

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

</project>
IDK
  • 359
  • 1
  • 16
  • `common-parent` doesn't seem to be referenced as a dependency in the `microservices-parent` pom.xml file you included – Ben Anderson Dec 01 '22 at 23:15
  • yeah, I tried it but it gives me the first of error in my question... basically it doesn't find the **common build** – IDK Dec 02 '22 at 05:22

0 Answers0