java – 如何包含pom项目中的所有模块
|
我正在寻找一种方法,从另一个pom.xml包含项目中的所有模块.所以在我的情况下,我有一个父pom,包装设置为pom.它包含3个子模块,用于在另一个api模块中实现我的接口.我想在maven中动态地包含我项目中的所有子模块. 在这种情况下,我想在另一个模块中包含connector1,connector2,connector3,而不必隐式指定connector1,2,3. connectors - packaging: pom connector1 - packaging: jar connector2 - packaging: jar connector3 - packaging: jar 我尝试在我的项目中包含连接器pom,但这不起作用.我希望用pom指定父包将包含子模块,但这不起作用.有没有解决方法如何做到这一点? 更新 这更像是我的阴影,因为我想简单地添加一个连接器并包含项目的所有子模块依赖关系jar.这将使pom更容易阅读. 而不必像这样注册所有子依赖项 <dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-api</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-etl</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1-persistence</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-api</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-etl</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-persistence</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2-other</artifactId>
<version>0.0.1</version>
</dependency>
...
</dependencies>
这只是澄清原始问题的一个例子.它不存在,如果确实有效,可能会有重新发布. <dependencies>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector1</artifactId>
<version>0.0.1</version>
<type>pom</type>
<include>submodules</include>
</dependency>
<dependency>
<groupId>com.foo</groupId>
<artifactId>connector2</artifactId>
<version>0.0.1</version>
<type>pom</type>
<include>submodules</include>
</dependency>
</dependencies>
如果我没记错的话,我正在为订购系统创建一个模块化项目,在那里我有一个内部系统将使用的通用API(REST).我正在创建一个路由系统,我可以根据订单的标准(国家,优先税等)将订单路由到单个履行中心.每个履行中心都有自己的api(连接器). 原始问题中的示例大大简化,使问题更简洁.在实际项目中,每个连接器(1,3)都是一个带有多个依赖jar的独立pom.一个用于他们的客户端api,然后一些etl代码与我原来的api匹配. 我不记得我是怎么解决这个问题的.我想我只需要包含所有子依赖项. 解决方法一种方法是创建第四个模块,将3个模块“包装”为依赖关系.这样你可以依赖这个包装器模块.connectors - packaging: pom connector1 - packaging: jar connector2 - packaging: jar connector3 - packaging: jar connectorWrapper - packaging: pom (depends on the above three) 虽然为每个连接器显式声明一个依赖项更有意义,特别是它们只有三个. 替代方案: 一个更动态的方法(虽然非常过分的IMO)是让第四个模块使用自定义assembly descriptor将实现模块打包到一个程序集中.例如,在connectorWrapper中,你可以编写一个assembly.xml: <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>impl-modules</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<includes>
<include>pom.xml</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>*:connector*</include>
</includes>
<binaries>
<includeDependencies>false</includeDependencies>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
请注意,描述符告诉程序集插件: >包括当前项目反应器中的所有模块,因此当您在根项目中运行mvn clean包时,它将包含所有模块 当然,您需要配置程序集插件以在connectorWrapper中使用此描述符(或者为此包装器选择的任何其他名称): <plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
然后,您可以在根项目上运行mvn install来安装程序集工件,之后您可以从其他项目依赖它: <dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>connectorWrapper</artifactId>
<version>...</version>
<classifier>impl-modules</classifier> <!-- note the classifier -->
</dependency>
</dependencies> (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
