0

Hello currently I have a parent git repo that houses two separate microservices written in Quarkus. For the ease of use within a CI/CD in the parent root folder I created a pom.xml that when I run a mvn package I want to be able to copy it into the parent/target/ path.

So the folder structure for instance is like this currently.

parent
  target
  pom.xml
  /microservice1
    - microservice1.jar
  /microservice2
    - microservice2.jar

but I want it to look like

parent
  target
  - microservice1.jar
  - microservice2.jar
  pom.xml
  /microservice1
  /microservice2

Since the parent folder/git repo doesn't have a pom.xml I generated one and this is what it looks like and I tried to use the maven-dependency-plugin suggestion that I found here

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>parent-service</artifactId>
  <version>1.0-SNAPSHOT</version>

  <packaging>pom</packaging>
  <modules>
      <module>microservice1</module>
      <module>microservice2</module>
  </modules>

  <name>parent-service</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>             
              <id>copy-artifact</id>
              <phase>package</phase>
              <goals>
                <goal>copy</goal>
              </goals>
              <configuration>
                <artifactItems>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>${project.artifactId}</artifactId>
                      <version>${project.version}</version>
                      <type>${project.packaging}</type>
                    </artifactItem>
                </artifactItems>
                <!--<outputDirectory>../Main/target/dependencies</outputDirectory>-->  
                <!--CHANGE IS HERE -->
                <outputDirectory>target</outputDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
    </plugins>
</build>
</project>

After running a mvn package at the parent folder the individual microservices are still packaging their own respective jars into microservice/target/ folders. Another weird interaction seems to be that the parent will just package it's own pom into it's own target/ folder. I could post the sub-microservices pom.xml files but those are quite long. What am I doing wrong? Did the way I create the pom not work well?

animusdx
  • 380
  • 3
  • 16
  • I am not sure this is a good idea. Why not let the CI/CD process read the files from where Maven places them? – J Fabian Meier Dec 08 '20 at 18:20
  • @JFabianMeier hey, I'm not handling the CI/CD pipeline but I've been told that it is so they can re-use the same CI/CD pipeline without having the user or whoever juggle with even more input variables. As in this minor example the parent directory only has two currently but can grow with even more microservices. Of course having all the microservices as a separate repo would make it easier but for maintainability this is how they want it. – animusdx Dec 08 '20 at 18:35
  • Actually, I would try with the maven antrun plugin which allows you to easily move files on the directory level. – J Fabian Meier Dec 08 '20 at 18:57

0 Answers0