[英]custom pom.xml filename in maven multimodule
我有一個maven3多模塊項目,由於一個奇怪的原因,我需要為我的一個子模塊自定義POM文件名(即:module-pom.xml)
是否可以在父pom中配置它?
奇怪的原因是有點長的解釋抱歉,但你會有簡單的背景。
上下文
我正在開發一個也使用LGPLed項目的閉源項目。 這個項目叫做main
我希望main
聲明每個項目的模塊,關閉和打開。 應使用唯一的mvn clean package
命令進行完整構建。
在main
反應堆項目中,我有lgpl-reactor
多模塊項目,包含3個LGPL模塊(API,插件和分發項目)。 有些開發人員只能訪問lgpl-reactor
,所以我也希望這個項目使用mvn clean package
命令從其文件夾構建,就像一個完全獨立的項目。
我還有main-dist
項目,它只是一個maven-assembly-plugin項目(用於構建發行版)。
問題
如果我添加對lgpl-reactor
pom.xml的父引用,則全局main
構建工作正常,並且main-dist
創建的程序集有效,但lgpl-reactor的獨立構建失敗(未找到主pom.xml)。
如果我從lgpl-reactor
pom.xml中刪除父引用,則獨立的lgpl-reactor
構建工作,但是由main-dist
創建的程序集無效(缺少。
怎么解決這個?
在main
模塊聲明列表中使用另一個POM文件module-pom.xml進行lgpl-reactor
模塊聲明。 當從main
項目執行完整構建時, module-pom.xml
包含對父POM的引用並且正常工作。
使用默認的POM文件pom.xml進行lgpl-reactor
構建。 此POM很難使用<parent>
標記的relativePath
屬性引用父pom
但我怎么能這樣做? 如果可能的話 ? 或者有更好的解決方案嗎?
主反應堆項目目錄
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]
LGPL反應堆項目目錄
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]
主反應堆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反應器/ 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>
...
main-dist
pom.xml
<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>
main-dist
assembly.xml
<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>
您可以覆蓋默認的pom.xml。 Maven有-f命令選項。
mvn -f <path>/pom.xml clean install
我建議將文件夾結構更改為以下內容。
root (pom.xml)
+-- closed-core
+-- closed-web
+-- closed-webserver
+-- closed-spring
+-- lgpl-reactor
+-- lgpl-lib
+-- lgpl-dist
+-- lgpl-etc..
比你不需要separte module-pom.xml文件。 您可以使用pom.xml作為默認值。
如果你不想建立lgpl-reactory,你可以簡單地給:
mvn -pl lgpl-reactory clean package
如果你在lgpl的其他模塊中有依賴關系,你可以使用:
mvn -am -pl lgpl-reactory clean package
這將構建所有依賴模塊。
一個解決方案是應用逆邏輯,並使用“mvn -f standalone-pom.xml clean package”來構建lgpl-reactor作為獨立項目...但是如果使用標准maven2構建獨立項目會更好命令行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.