我找不到一个好的、可扩展的解决方案的问题:
我有一个项目可以提供给定工件的多种风格。这是一个多模块项目,目前有 3 个模块:
- /flavor1_模块
- /flavor2_模块
- /flavor3_模块
问题是我还有另外 50 个项目需要以相同的方式设置,即提供 3 种风格。
考虑的解决方案:
- turning the already created multimodule project into a parent for all other 50 projects
-
Cons:它就是行不通。保留在父模块中的指令不会被继承,因此它们不会被执行。
- using maven-archetype-plugin http://maven.apache.org/archetype/maven-archetype-plugin/ to create a multi-module project
template http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-multi-module-project.html, and then creating all 50 projects based on the template
-
Cons:如果我需要flavor4,我需要手动更新所有50个项目以添加flavor4_module(并复制其内容)。不可扩展。
- embedding the configuration of all flavours into a single pom and enable or disable them based on profiles (i.e. using composition by profiles instead of inheritance via modules). Then pointing the 50 projects to it, as their parent. This would create "inline" modules
-
Cons:我需要实现我自己的机制,这些机制是由开箱即用的模块提供的。 (例如,在单独的目录中构建每种风格)。我还会失去模块提供的清晰分离。
有什么想法如何做得很好吗?还有其他选择吗?
谢谢,
卢卡斯
Edit:
另一种选择是延长Maven Reactor 插件 http://maven.apache.org/plugins/maven-reactor-plugin/index.html with 反应器:注入模块目标,它将从外部工件下载模块定义,并将其定义附加为普通模块。这将动态创建一个新模块。然后所有 50 个项目都可以将此 pom.xml 作为其父项目。
配置看起来像这样(草案):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-reactor-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>inject</id>
<phase>initialize</phase>
<goals>
<goal>inject-modules</goal>
</goals>
<configuration>
<modules>
<module>
<artifactId>flavour1_module</artifactId>
<groupId>[ groupId ]</groupId>
<version>[ version ]</version>
</module>
<module>
<artifactId>flavour2_module</artifactId>
<groupId>[ groupId ]</groupId>
<version>[ version ]</version>
</module>
<module>
<artifactId>flavour3_module</artifactId>
<groupId>[ groupId ]</groupId>
<version>[ version ]</version>
</module>
</modules>
</configuration>
</execution>
</executions>
</plugin>
走这条路有意义吗?
Update:
编写一个操纵要执行的模块列表的插件(我上面描述的模块注入的想法)似乎不可能实现,因为模块是由maven核心处理的,并且该机制并不是设计来扩展的一个插件。这两个插件执行类似的工作,即操作要执行的项目列表,这一事实证实了这一点:
- Maven Reactor 插件 http://maven.apache.org/plugins/maven-reactor-plugin/index.html
- maven-invoker-插件 http://maven.apache.org/plugins/maven-invoker-plugin/
通过执行系统调用来创建 Maven 子进程来实现这一点。对我来说,这不是可行的方法,因为这是一个非常不稳定的解决方案。的确Maven Reactor 插件 http://maven.apache.org/plugins/maven-reactor-plugin/index.html became 不相容 https://cwiki.apache.org/MAVEN/maven-3x-plugin-compatibility-matrix.html与 Maven3.
maven-invoker-插件 http://maven.apache.org/plugins/maven-invoker-plugin/看起来仍然很有希望。该插件最初设计用于运行集成测试,但可以使用它来扩展,例如编译阶段。
但它要求将子 pom.xml-s 视为资源并动态修改。对于我在这里描述的问题,解决方案过于复杂且不稳定。我更喜欢一些更轻的东西,可以在构建 Maven 模型时在内存中运行。
所以现在我使用配置文件,试图使它们尽可能紧凑。也许过一段时间我需要再次思考这个问题。
现在您可以使用行家瓷砖 https://github.com/maoo/maven-tiles/插件以获得所需的行为。
使用 maven-tiles,您可以在不同的 pom 中定义构建行为,import他们无论你喜欢在哪里。
附有一个工作示例MNG-5102 http://jira.codehaus.org/browse/MNG-5102?focusedCommentId=310175#comment-310175 --> 爸爸3.zip http://jira.codehaus.org/secure/attachment/61530/daddy3.zip
Maven 的仅限继承的紧身衣现已正式去除。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)