I have a maven3 multimodule project, and for a strange reason i need to customize POM filename for one of my child module (ie: module-pom.xml)
Is it possible to configure this in the parent pom ?
The strange reason is a bit long to explain sorry, but you will have the plain context.
Context
I'm working on a closed source project that also use LGPLed projects. this project is called main
I want main
to declare modules of every projects, closed and opened. The full build should be made with a unique mvn clean package
command.
Inside the main
reactor project, i have lgpl-reactor
multimodule project containing 3 LGPL modules (API, Plugins and Distribution project). Some developper will have access to lgpl-reactor
only, so i also want this project to build from its folder with mvn clean package
command, like a fully standalone project.
I also have main-dist
project that is a maven-assembly-plugin only project (to build the distribution).
The problem
If I add parent reference to lgpl-reactor
pom.xml, the global main
build works perfectly, and assembly created by main-dist
is valid, but the standalone build of lgpl-reactor fails (main pom.xml not found).
If I remove parent reference from lgpl-reactor
pom.xml, the standalone lgpl-reactor
build works, but assembly created by main-dist
is NOT valid (missing.
How to solve this ?
use another POM file module-pom.xml for lgpl-reactor
module declaration inside main
modules declaration list. When perfoming the full build from main
project, module-pom.xml
contains reference to parent POM and is working properly.
use the default POM file pom.xml for standalon build of lgpl-reactor
. This POM can hardly reference the parent pom with the relativePath
property of <parent>
tag
But HOW can i do that ? if possible ? Or is there any better solution ?
Directory of the Main Reactor Project
lgpl-lib [LGPL Library]
lgpl-ext [LGPL Reactor Project]
closed-core [Closed source module]
closed-spring [Closed source module]
closed-web [Closed source module]
closed-webserver [Closed source module]
main-dist [Main assembly module]
pom.xml [Main Reactor POM]
Directory of the LGPL Reactor Project
lgpl-api [LGPL API module]
lgpl-plugins [LGPL Plugins module]
lgpl-ext-dist [LGPL assembly module]
main-pom.xml [Main Reactor POM, copy of main pom.xml]
pom.xml [Standalone LGPL Reactor POM]
module-pom.xml [Module LGPL Reactor POM]
Main Reactor POM (pom.xml & lgpl-reactor/main-pom.xml)
...
<modelVersion>4.0.0</modelVersion>
<groupId>main.group</groupId>
<artifactId>main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Main</name>
<packaging>pom</packaging>
...
<modules>
<module>closed-core</module>
<module>closed-web</module>
<module>closed-webserver</module>
<module>closed-spring</module>
<module>lgpl-reactor</module>
<module>lgpl-lib</module>
<module>main-dist</module>
</modules>
...
lgpl-reactor/pom.xml
...
<modelVersion>4.0.0</modelVersion>
<artifactId>lgpl-reactor</artifactId>
<name>LGPL Reactor</name>
<packaging>pom</packaging>
<parent>
<groupId>main.group</groupId>
<artifactId>main</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>main-pom.xml</relativePath>
</parent>
...
...
<modules>
<module>lgpl-api</module>
<module>lgpl-plugins</module>
<module>lgpl-ext-dist</module>
</modules>
...
pom.xml of main-dist
<project>
<parent>
<groupId>main.group</groupId>
<artifactId>main</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>main-dist</artifactId>
<packaging>pom</packaging>
<description>Main Distribution</description>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>plugins-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>closed</groupId>
<artifactId>closed-webserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>closed</groupId>
<artifactId>closed-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
assembly.xml of main-dist
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>plugins-assembly</id>
<formats>
<format>dir</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>../closed-webserver/conf</directory>
<outputDirectory>conf</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<excludes><exclude>main.group:closed-webserver</exclude></excludes>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>main.group:closed-webserver</include>
</includes>
<binaries>
<outputFileNameMapping>${module.artifactId}${dashClassifier?}.${module.extension}</outputFileNameMapping>
<unpack>false</unpack>
<includeDependencies>false</includeDependencies>
</binaries>
</moduleSet>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>main.group:closed-spring</include>
</includes>
<binaries>
<outputFileNameMapping>${module.artifactId}${dashClassifier?}.${module.extension}</outputFileNameMapping>
<unpack>false</unpack>
<includeDependencies>false</includeDependencies>
</binaries>
</moduleSet>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>main.group:lgpl-ext-dist</include>
</includes>
<binaries>
<outputDirectory>plugins</outputDirectory>
<unpack>false</unpack>
<includeDependencies>true</includeDependencies>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
You can override default pom.xml. Maven have -f command option.
mvn -f <path>/pom.xml clean install
I would suggest to change the folder structure into the following.
root (pom.xml)
+-- closed-core
+-- closed-web
+-- closed-webserver
+-- closed-spring
+-- lgpl-reactor
+-- lgpl-lib
+-- lgpl-dist
+-- lgpl-etc..
Than you don't need a separte module-pom.xml file. You can work with pom.xml as default.
If you wan't to build lgpl-reactory you can simply give:
mvn -pl lgpl-reactory clean package
if you have dependencies within the other modules to lgpl you can use:
mvn -am -pl lgpl-reactory clean package
This will build also all dependent modules.
一个解决方案是应用逆逻辑,并使用“mvn -f standalone-pom.xml clean package”来构建lgpl-reactor作为独立项目...但是如果使用标准maven2构建独立项目会更好命令行。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.