Fabric8 Docker Maven plugin not working for compose.yml on Multi module project - maven

I trying to use Fabric8 docker-maven-plugin, though I was successful in configuring plugin for individual module and run docker:build docker:start Maven goal without using docker-compose.yml, however I needed externalize ports and link the different module, hence I intended to use docker-compose.yml. Below is my project structure.
--kp-parent
|
--- docker-compose.yml
--- pom.xml
|
---- rest1
| |
| -- .maven-dockerignore
| -- pom.xml
| -- Dockerfile
---- rest2
| |
| -- .maven-dockerignore
| -- pom.xml
| -- Dockerfile
Here are my configurations
Dockerfile[both rest1 and rest2 use identical file except the different port]
FROM openjdk:8-jdk-alpine
MAINTAINER 'Karthik Prasad'
ARG IMAGE_VERSION
ARG JAR_FILE
ENV JAVA_OPTS=""
LABEL version = IMAGE_VERSION
VOLUME /tmp
ADD /maven/${JAR_FILE}.jar app.jar
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
EXPOSE 8000
.maven-dockerignore[In both child modules identical file]
target/**
pom.xml [Both rest1 and rest2 pom files are same except the artifcatid and name of the project]
<?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>
<artifactId>rest2</artifactId>
<packaging>jar</packaging>
<name>rest2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.kp.swasthik</groupId>
<artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- https://mvnrepository.com/artifact/io.fabric8/docker-maven-plugin -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<images>
<image>
<external>
<type>compose</type>
<basedir>../</basedir>
<ignoreBuild>true</ignoreBuild>
</external>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
parent pom.xml
<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.kp.swasthik</groupId>
<artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>kp-docker-multimodule-fabric8-parent</name>
<description>Microservice Parent Pom file</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<modules>
<module>rest1</module>
<module>rest2</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker.image.prefix>kp-ms</docker.image.prefix>
</properties>
<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>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.22.1</version>
<configuration>
<skip>true</skip>
<images>
<image>
<alias>${project.artifactId}</alias>
<name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
<build>
<dockerFileDir>${project.basedir}</dockerFileDir>
<assembly>
<inline>
<id>default</id>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</inline>
</assembly>
</build>
</image>
</images>
<buildArgs>
<IMAGE_VERSION>${project.version}</IMAGE_VERSION>
<JAR_FILE>${project.artifactId}-${project.version}</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
And finally docker-compose.yml
version: '2'
services:
rest1:
image: kp-ms/rest1:0.0.1-SNAPSHOT
ports:
- 8000:8000
rest2:
image: kp-ms/rest2:0.0.1-SNAPSHOT
ports:
- 8001:8001
links:
- rest1
When I run the docker:build docker:start I get below error.
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:start (default-cli) on project rest1: I/O Error: Unable to pull 'kp-ms/rest2:0.0.1-SNAPSHOT' : repository kp-ms/rest2 not found: does not exist or no pull access (Not Found: 404) -> [Help 1]
[ERROR]
However If I remove rest2 section in docker-compose.yml, build goes fine and I'm able to find the container start successfully.
Another problem I noticed is that even if do not give image name in docker-compose.yml build fails with error image is null. However I'm not sure why I need to provide image can't the plugin map from plugin configuration as I had provided alias. As you can notice I'm trying to generate image name dynamically.

Related

Spring-boot local repository 2.7.5 not working

an attempt to work with local repository of spring-boot project
failing according to intellij, but project is compiling and dependencies exist.
is it possible the all is good , but intellij error flag is wrong ?
<?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.example</groupId>
<artifactId>project-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>project-manager</name>
<description>project-manager</description>
<properties>
<java.version>11</java.version>
<apache.poi.version>5.2.2</apache.poi.version>
<fasterxml.jackson.version>2.14.1</fasterxml.jackson.version>
</properties>
<dependencies>
... dependencies
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
worked fine with central-repository on parent version 2.7.5
worked fine with local repository on parent 2.3.0-RELEASE
thanks.
in case someone get same issue , solution:
Intellij (v 2021.3.3)
press
"File | Invalidate Caches" fixed the issue.
jetbrain support

Create EAR Project With SpringBoot module

I need to create an EAR file to be deployed on JBoss EAP 7. I considered to build a project structure like the following:
- rootproject
-- ear (ear)
-- web (war)
Therefore for the rootproject I have created a new Simple Maven project (using Eclipse 06/2020), with the following .pom.xml:
<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>jboss_test</groupId>
<artifactId>jboss_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>jboss_ear_test</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.11.RELEASE</version>
</parent>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>ear</module>
<module>web</module>
</modules>
</profile>
</profiles>
</project>
Therefore, inside it, I have created a SpringBoot 2.2.11 project (WEB) with the following .pom.xml:
....
....
<parent>
<artifactId>jboss_test</artifactId>
<groupId>jboss_test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<packaging>war</packaging>
<name>web-test</name>
<description>Spring Boot JBOSS</description>
.... // some dependencies
And a Maven module used the ear with the following .pom.xml:
....
....
<parent>
<artifactId>jboss_test</artifactId>
<groupId>jboss_test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ear</artifactId>
<packaging>ear</packaging>
<name>ear-test</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>JBOSS-TEST_EAR</finalName>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>jboss_test</groupId>
<artifactId>web</artifactId>
<bundleFileName>JBOSS-TEST.war</bundleFileName>
<contextRoot>/TEST</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
When I try to build the project from its root I obtain the following error:
Artifact[war:jboss_test:web] is not a dependency of the project
Can you help me to find out whats wrong??
Thank you
Thanks a lot to #khmarbaise for his response, I solved as follows:
Creating rootproject as Simple Maven project, .pom.xml:
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.11.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>ear-test</module>
<module>web-test</module>
</modules>
Creating ear-test as Maven module, .pom.xml:
<parent>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ear-test</artifactId>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>TEST-EAR</finalName>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>web-test</artifactId>
<bundleFileName>WEB-TEST.war</bundleFileName>
<contextRoot>/WEB-TEST</contextRoot>
</webModule>
</modules>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Implementation-Title>JBOSS-TEST</Implementation-Title>
<Implementation-Version>1.0</Implementation-Version>
<Implementation-Vendor>CODING</Implementation-Vendor>
<Built-By></Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>web-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
Creating web-test as SpringBoot 2.2.11 project, .pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>web-test</artifactId>
<packaging>war</packaging>
<name>web-test</name>
<description>Spring Boot JBOSS</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
// dependencies
</dependencies>
...
...
</project>
Maven build goes fine and EAR is created.. Than I would like to ask one more thing: do you think I have to define all the dependecies inside my ear-test pom?? Also those of the web-test project related to Spring, Hibernate etc.. ?
Thanks a lot

How do you configure a Maven/SpringBoot Project's pom.xml for docker?

I am attempting to dockerize my SpringMVC application via Maven. My intent is to have an image that I can then proceed to expose and display via my web browser.
Unfortunately, in following this guide, I appear to still lack a critical piece of understanding concerning the pom.xml edits I must make to achieve this, and the Dockerfile.
======
Here is the Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
======
Here is the source code's pom.xml in its latest revision.
======
Here is my latest attempt at revision, in following the example pom.xml of the SpringIO guide I referenced above (dependencies section not included).
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.davidonus</groupId>
<artifactId>davidonusSpringDemo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- tag::packaging[] -->
<packaging>jar</packaging>
<name>davidonusSpringDemo1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<!-- tag::docker[] -->
<docker.image.prefix>springio</docker.image.prefix>
</properties>
<profiles>
<profile>
<id>DavidSpringTime</id>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
</configuration>
</plugin>
<!-- end::plugin[] -->
<!-- tag::unpack[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- end::unpack[] -->
</plugins>
</build>
Here are my present results, using the command mvn install build:docker
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.050 s
[INFO] Finished at: 2019-06-15T13:24:01-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:unpack (unpack) on project davidonusSpringDemo1: Unable to update Marker timestamp: /home/david/Desktop/DevOps2019/springBoot/teluskoSpringBoot/target/dependency-maven-plugin-markers/com.davidonus-davidonusSpringDemo1-jar-0.0.1-SNAPSHOT.marker: Unable to update last modified timestamp on marker file /home/david/Desktop/DevOps2019/springBoot/teluskoSpringBoot/target/dependency-maven-plugin-markers/com.davidonus-davidonusSpringDemo1-jar-0.0.1-SNAPSHOT.marker -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
======
In summary, given my original pom.xml, what changes would you implement to make my SpringBoot + Maven project deployable as a docker image and container?
Furthermore, are there adaptions to my Dockerfile that you'd make? Your consultation is appreciated. Thank you.
If you have your springboot code ready with pom.xml. Then follow below steps to containerize your application.
git clone https://github.com/dnmorris7/teluskoSpringBoot (I'm cloning your springboot code)
git checkout module5 (checked out module5 branch)
Created Dockerfile in your git codebase with following contents:
FROM maven:3.6-jdk-8-slim AS build
COPY . /usr/src/app/
WORKDIR /usr/src/app/
RUN mvn -f /usr/src/app/pom.xml clean package
FROM java:8-alpine
WORKDIR /
COPY --from=build /usr/src/app/target/*.jar /app.jar
CMD java -jar app.jar
NOTE: I'm using docker multi-stage build where in first stsage maven builds the jar and in the second stage we copy that jar in java image.
Now build your docker image docker build -t appimage:v1 .
Run your docker container docker run -it -d -p 9090:9090 appimage:v1
Hit the api to check if its working fine.
$ curl localhost:9090/home
{"timestamp":"2019-06-16T05:34:26.655+0000","status":404,"error":"Not Found","message":"/pages/home.jsp","path":"/home"}
Please hit the correct base url, I tried with /home
NOTE: If you want to provide your own custom application.properties then change the java -jar command in Dockerfile to CMD java -jar app.jar --spring.config.additional-location=application.properties and change the docker run command to docker run -it -d -v application.properties:/application.properties -p 9090:9090 appimage:v1 where application.properties is the one which you provide from outside.
I think not much is missing. Or even better there may be even too many things.
First, you need to tell the docker maven plugin to run. The maven lifecycle defines which plugins run at what phase. So all other plugins need an execution configuration somewhere (in a parent pom or in yours). Second, there is no need to unpack the created jar file. Spring Boot will create an executable jar file automatically. You only need to tell the docker maven plugin about it (where it is created)
This would be the Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/myapp.jar
ENTRYPOINT ["java","-jar","/usr/share/myapp.jar"]
And this your pom:
<?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>org.springframework</groupId>
<artifactId>gs-spring-boot-docker</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>Spring Boot Docker</name>
<description>Getting started with Spring Boot and Docker</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath />
</parent>
<properties>
<docker.image.prefix>springio</docker.image.prefix>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
<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>
</dependencies>
</project>
The unpack goal of the dependency plugin can be removed. This way the jar is added into the image and run directly. Hope it works!

service bus maven error - unknown packaging sbar

I am new to maven / pom.xml and am following the below link to create an oracle service bus project and package it into custom packaging type "sbar".
https://docs.oracle.com/middleware/1213/core/MAVEN/osb_maven_project.htm#MAVEN8971
The Project gets generated properly (from the command --> mvn archetype:generate ... ) but when I execute the below command I get an error
mvn package -DoracleHome=/path/to/osbhome
[ERROR] Unknown packaging: sbar # line 16, column 16
project pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.oracle.servicebus.plugin</groupId>
<artifactId>oracle-servicebus-plugin</artifactId>
<version>12.1.3-0-0</version>
</parent>
<groupId>my-servicebus-application</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sbar</packaging> <!--getting error on this line-->
<build>
<plugins>
<plugin>
<groupId>com.oracle.servicebus.plugin</groupId>
<artifactId>oracle-servicebus-plugin</artifactId>
<version>12.1.3-0-0</version>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
application pom.xml
<project>
...
<modelVersion>4.0.0</modelVersion>
<groupId>my-servicebus-application</groupId>
<artifactId>my-servicebus-application</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>System</module>
<module>my-project</module>
</modules>
...
</project>
system pom.xml
<project>
...
<modelVersion>4.0.0</modelVersion>
<groupId>org.mycompany</groupId>
<artifactId>System</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sbar</packaging>
<parent>
<groupId>com.oracle.servicebus</groupId>
<artifactId>sbar-system-common</artifactId>
<version>12.1.3-0-0</version>
<relativePath></relativePath>
</parent>
...
</project>
I am using JDeveloper 12.1.3.0.0 and Maven 3.0.5.
(I get the same error if I run it either from JDeveloper or from command promt)
Please help me solve this error.
Thanks in Advance !
I haven't really sat down to work with any of the Maven POM's for OSB, SOA, etc., but I do know that your maven plugin probably isn't on the default M2 repository. It probably can't find your packaging type of sbar because it's not included in your repository. I'm assuming you're using their supplied maven and maven repo following this guide: https://docs.oracle.com/middleware/1213/core/MAVEN/config_maven.htm#MAVEN8853

Dependency management does not work for multi-module project

I have a Maven project with multiple modules and I'm trying to set it up so that module dependencies are automatically built to the correct lifecycle phase needed for building depending modules to the requested lifecycle phase.
In the example, the module plugin builds a Maven plugin, which is used to generate source code and is used by the module main. If I just try to use mvn -am -pl main compile, the module plugin is compiled but the process-classes lifecycle phase is not executed (which is necessary for a plugin to be usable). Compiling the module main then fails then with the following error:
[ERROR] Failed to parse plugin descriptor for example:plugin:1.0.0-SNAPSHOT (/Users/ims/Dropbox/IMS/Projects/PARITy_R4/codegen-test-simple/plugin/target/classes): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
Is Maven, or a plugin for it, capable of resolving the dependencies of modules in a multi-module project and build them to stage necessary by other modules? And if so, how do I need to set up the project for this to work?
These are the POMs of my project:
pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>plugin</module>
<module>main</module>
</modules>
</project>
plugin/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<parent>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<goalPrefix>configurator</goalPrefix>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
main/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>example</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>codegen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If you look at the reference documentation for the Maven lifecycle, you'll see that compile is before process-classes.
If you want this step to happen, you need to use mvn -am -pl main process-classes instead.
But I suggest that you always use mvn ... install - it also runs the tests and makes sure that the plugin which main uses is actually the one you think it should: Without install, the build will use an old/outdated version from the local repository (Maven will not magically determine "oh, there is a plugin in my reactor, I'll use that instead of the version from the local repo").

Resources