Home > Software design >  Multi-module Maven project : child C require child B but build error telling parent A is not found
Multi-module Maven project : child C require child B but build error telling parent A is not found

Time:11-26

I have a problem when building specific module of my Maven projects Project structure is like this :

data-importer (parent A)

|____ spring-batch (child B, jar)

|____ docker (child C)

I'm using IntelliJ (but tried with CLI and same behaviour) to build, when I'm building from the parent pom there is no problem but when I'm trying to build firstly spring-batch then docker I have the current error :

Could not find artifact ***.****.****.****:data-importer:pom:develop in nexus (http://**********/repository/maven-dev-group/)

I don't know why it's trying to get parent's pom, even if I have defined relativePath in child's POMs

I have the following POM (without the confidential parts) :

data-importer (parent A)

<?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>

   <groupId>*******</groupId>
   <artifactId>data-importer</artifactId>
   <version>develop</version>
   <packaging>pom</packaging>
   <name>data-importer</name>

   <description>data importer application for *</description>

   <parent>
      <groupId>*****.*****.******</groupId>
      <artifactId>super-pom</artifactId>
      <version>2.2.1-SNAPSHOT</version>
      <relativePath/>
   </parent>

   <properties>
      some versions
   </properties>

   <modules>
      <module>spring-batch</module>
      <module>docker</module>
   </modules>

   <dependencies>
      <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-all</artifactId>
         <scope>compile</scope>
      </dependency>
   </dependencies>

   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>*.*.*.*</groupId>
            <artifactId>data-importer-spring-batch</artifactId>
            <version>${project.version}</version>
         </dependency>
      </dependencies>
   </dependencyManagement>

</project>

**spring-batch (child A) **

<?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>****.****.**.***</groupId>
        <artifactId>data-importer</artifactId>
        <version>develop</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>data-importer-spring-batch</artifactId>
    <version>develop</version>
    <packaging>jar</packaging>
    <name>spring-batch</name>

    <description>data importer application for *</description>

    <dependencies>
        some dependencies
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring.boot.version}</version>
                <executions>
                    <execution>
                        <id>data-importer</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            one dependency
        </dependencies>
    </dependencyManagement>

</project>

docker (child C)

<?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>*.*.*.*</groupId>
        <artifactId>data-importer</artifactId>
        <version>develop</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>scpas-import</artifactId>
    <version>develop</version>
    <packaging>pom</packaging>
    <name>docker</name>

    <description>data importer application for docker</description>

    <profiles>
        <!-- Profil commun pour générer les images docker -->
        <profile>
            <id>docker</id>
            <build>
                <finalName>${project.artifactId}</finalName>
                <plugins>
                    <!--Copy du jar spring batch dans target/docker/volumes/transferdata/import/data-importer -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-data-importer-jar-files</id>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <includeGroupIds>*.*.*.*</includeGroupIds>
                                    <includeArtifactIds>data-importer-spring-batch</includeArtifactIds>
                                    <type>jar</type>
                                    <outputDirectory>
                                        ${project.build.directory}/docker/volumes/transferdata/import/data-importer/
                                    </outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/docker</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${basedir}/database</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>**/*</include>
                                            </includes>
                                        </resource>
                                        <resource>
                                            <directory>${basedir}/data-importer</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>**/*</include>
                                            </includes>
                                        </resource>
                                        <resource>
                                            <directory>${basedir}</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>Dockerfile</include>
                                            </includes>
                                        </resource>
                                        <resource>
                                            <directory>${basedir}</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>docker-compose.data-importer.yml</include>
                                            </includes>
                                        </resource>
                                        <resource>
                                            <directory>${basedir}</directory>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>docker-entry-point.sh</include>
                                            </includes>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!--Génération de image docker-->
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build-image</id>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <dockerDirectory>${project.build.directory}/docker</dockerDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>
                docker-push
            </id>
            some steps to push image in our registry
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>*.*.*.*</groupId>
            <artifactId>data-importer-spring-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>compile</scope>
        </dependency>
    </dependencies>

</project>

Any idea why it's trying to get parent POM from registry ? (I don't want to push it as a mvn dependency)

Thx

I tried some tricks in settings.xml to never pull snapshots and releases from registry but nothing works except building full project from parent's POM

CodePudding user response:

Since access to the parent-POM is given, you can just locally install it beforehand.

This will solve looking parent up a repository.

What you need is to call Maven with -N (non-recursively) option mvn install -N and then you should be able to use it.

  • Related