In maven multimodule project, there is a submodule that needs to inherit from external parent project. Therefore it cannot inherit from the parent module as other submodules, and those cannot inherit that external parent (so making the external project the parent of the entire hierarchy is not an option).
Is there a way to eliminate the duplication of properties between such module and the rest of the hierarchy?
parent pom.xml
<properties>
<foo>bar</foo>
</properties>
<modules>
<module>child</module>
<module>stepchild</module>
</modules>
child pom.xml
<parent>
<groupId>my</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<description>foo can be used: ${foo}</description>
stepchild pom.xml
<parent>
<groupId>external</groupId>
<artifactId>parent</artifactId>
<version>35</version>
<relativePath/>
</parent>
<description>foo does not get substituted: ${foo}</description>
beside all problems found by other users in comments above, you can set properties using a reusable file 'my.properties' containing
foo=bar
and adding to maven:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/../project-parent/my.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Related
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?
I am trying to find a good example on how you would build multiple zip files for a multi-module project with several runnable components using the maven-assembly-plugin.
My end result would hopefully have a single "dist" component that is capable of building all the necessary zip files.
<?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>
<parent>
<groupId>xyz.exampleproject</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<name>Project Distribution</name>
<artifactId>dist</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>component1-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>component2-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-bundles</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I would add one extra module per zip file that you want to create and configure the assembly plugin in there.
I am trying to build a single uber-jar from a set a modules that are mostly independent, but it's not working the way I'd thought.
I was initially directed here: https://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html though now I'm not quite certain that this was what I should have started with...
The parent pom file looks like this:
<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.mycompany</groupId>
<artifactId>BigProject</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>BigProject</name>
<modules>
<module>../mod1</module>
<module>../mod2</module>
<!-- ...a bunch more... -->
<module>../distribution</module>
</modules>
<build>
<pluginManagement>
<plugins>
<!-- not even sure why this needs to be specified here, but the documentation seems to think it's important... -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The pom for the "distribution" module looks like this:
<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>distribution</artifactId>
<name>distribution</name>
<packaging>pom</packaging>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>BigProject</artifactId>
<version>0.0.1</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And finally, the assembly file:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>bin</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<includeSubModules>true</includeSubModules>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.myCompany:mod1</include>
<include>com.myCompany:mod2</include>
<!-- and others... -->
</includes>
<binaries>
<includeDependencies>true</includeDependencies>
<outputDirectory>modules/maven-assembly-plugin</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
(I realize that at some point I will probably need to change <format>dir</format> to <format>jar</format> but for now, I'd just like to get something working)
When I run mvn clean package from the main parent module's directory, I get warnings like this:
[INFO] Reading assembly descriptor: src/assembly/assembly.xml
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o 'com.myCompany:mod1'
o 'com.myCompany:mod2'
...
Followed by the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:3.1.0:single (distro-assembly) on project distribution: Failed to create assembly: Error creating assembly archive bin: archive cannot be empty -> [Help 1]
What I actually want:
One jar file containing all of my modules, and all of their dependencies (that is, the *-with-dependencies.jars), as a single jar file with everything contained inside.
I'm really not sure how to achieve this in a multi-module context.
I think I may have resolved it: the child modules mod1, mod2, ... were missing the parent module dependency. I've added
<parent>
<groupId>com.mycompany</groupId>
<artifactId>BigProject</artifactId>
<version>0.0.1</version>
</parent>
to the relevant child modules and now the build doesn't fail, but populates the target directory under the distribution project.
I was upgrading the Spring version of our project and I noticed that the src/ folder doesn't appear as classes when I open the file as an Archive. Instead all I found was an /org folder where I found Spring.
It actually looked like this,
The strange thing was that we got the classes nicely before (as you would expect in JARs) in Spring 1.3.x.RELEASE
My pom.xml looks like this,
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<groupId>spring.mvn</groupId>
<artifactId>dummySpringMvn</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<mvn.compiler.version>3.3</mvn.compiler.version>
<spring.framework.version>4.3.8.RELEASE</spring.framework.version>
<start-class>dummySpringMvn.main.Main</start-class>
</properties>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I found my classes in BOOT-INF folder!
This I found thanks for the article https://docs.spring.io/spring-boot/docs/current/reference/html/executable-jar.html.
Furthermore, the project I upgraded was a library to another project. I was able to keep the folder of JARs as conventional creating the JAR without invoking spring-boot-maven-plugin
I am trying to transform a working single GWT-Project into several Maven-Modules.
New structure should look like this:
Project
|- pom.xml
|- Project-Common(only Common-Classes)
|--- pom.xml
|--- Packaging: jar
|- Project-War(includes *gwt.xml)
|--- pom.xml
|--- Packaging: war
My files look like this(many dependencies, I think i removed the unnecessary to make my problem more clear)
Project pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project</artifactId>
<packaging>pom</packaging>
<name>Project - Modules</name>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent-parent</artifactId>
<version>2.0.0</version>
<relativePath />
</parent>
<modules>
<module>/project-war</module>
<module>/project-common</module>
</modules>
Project-Common pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project-common</artifactId>
<packaging>jar</packaging>
<name>Project - Common</name>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.project</groupId>
<artifactId>project-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath />
</parent>
<build>
<plugins>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<executions>
<execution>
<id>load-git-branch</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
<configuration>
<dirtyFlag>*</dirtyFlag>
<gitDir>../../.git</gitDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Project-War pom.xml:
<modelVersion>4.0.0</modelVersion>
<artifactId>project-war</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Project - WAR</name>
<parent>
<groupId>com.project</groupId>
<artifactId>parent-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<inherited>true</inherited>
<configuration>
<runTarget>/test.html</runTarget>
<modules>
<module>com.project.modules.Test</module>
</modules>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<id>VerifyRequestFactoryInterfaces</id>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath />
<argument>com.google.web.bindery.requestfactory.apt.ValidationTool</argument>
<argument>${project.build.outputDirectory}</argument>
<argument>com.project.factorys.TestRequestFactory</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>src/main</directory>
<includes>
<directory>gwt-unitCache/**</directory>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>com.github.koraktor</groupId>
<artifactId>mavanagaiata</artifactId>
<executions>
<execution>
<id>load-git-branch</id>
<phase>validate</phase>
<goals>
<goal>commit</goal>
</goals>
<configuration>
<dirtyFlag>*</dirtyFlag>
<gitDir>../../.git</gitDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The old Project was in my Project-War and I added Project & Project-Common. In this setup the Project builds and I get the "new" Project-War.war .
But when I move a ErrorCode.java from Project-War to Project-Common I get the following Error:
[INFO] Tracing compile failure path for type 'com.project.modules.TestViewImpl'
[INFO] [ERROR] Errors in '.../project/project-war/src/main/java/com/project/modules/TestViewImpl.java'
[INFO] [ERROR] Line 20: No source code is available for type com.project.errorcodes.ErrorCode; did you forget to inherit a required module?
[INFO] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Your Project-Common doesn't package its sources to be available to the Project-War, so GWT effectively can't find the source for ErrorCodes class.
You have to either use the maven-source-plugin's jar-no-fork goal in Project-Common to package sources, and then add a second dependency on Project-Common in Project-War with <classifier>sources</classifier>; or declare your src/main/java as a resource directory to package sources into the Project-Common's JAR.
As a side note, Mojo's Maven Plugin for GWT isn't a great fit for multi-module projects. I'd advise switching to the net.ltgt.gwt.maven:gwt-maven-plugin which was designed for multi-module builds from the ground up (disclaimer: I'm the author of that plugin, and former maintainer of Mojo's plugin)
Found a Solution:
Added a Module in Common-Project
<module>
<inherits name='com.google.gwt.activity.Activity' />
<inherits name='com.google.gwt.place.Place' />
<inherits name="com.google.gwt.user.User" />
<inherits name='com.google.web.bindery.requestfactory.RequestFactory' />
<inherits name="com.google.gwt.user.cellview.CellView" />
<inherits name='com.google.gwt.logging.Logging' />
<inherits name="com.google.gwt.inject.Inject" />
<inherits name="com.google.gwt.text.Text" />
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.debug.Debug" />
<source path="shared"/>
</module>
any my ErrorCode.java is under Path shared/** .
In Project-War Modules I added <inherits name="com.project.Common" /> and in pom.xml from Project-War:
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.project</groupId>
<artifactId>project-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
Seems to need dependency with classifier in scope provided.