我一直在努力让 Maven2 与我合作,并且想知道是否有人对如何让它工作有任何想法......我正在开发一个 Flash 项目,我们正在考虑从我们的混合 Flex4/FlashCS4 到纯 Flex4 解决方案。我们想使用 Maven2 构建系统,这样我们的开发人员就不必在他们的机器上手动下载、安装和配置 Flex4。
我已经成功地使用 Maven2 和 Flex4 创建了一个单模块项目(我正在使用 Sonatype FlexMojos 插件及其位于 http://repository.sonatype.org/content/groups/flexgroup/ 的 Maven2 存储库)。在制作这个多模块时,我真的开始遇到麻烦了......
我们的项目组织如下:
|- bin | |- moduleX.swf | |- moduleY.swf | |- ... |- lib | |- moduleA.swc | |- moduleB.swc | |- ... |- src | |- moduleA | |- moduleB | |- ... |- test | |- moduleA | |- moduleB | |- ... |- share | |- asset1 | |- asset2 | |- ... |- ...
基本上,我们每个模块的源代码都位于“src/
最佳答案
如果您确定要迁移到 Maven 2,那么修改项目结构让每个模块都包含自己的源代码和测试并遵循 Maven 约定会省去很多麻烦。
如果您真的做不到,您可以创建一个并行模块层次结构,并使用指向现有结构的相对路径配置每个模块。该结构最终可能看起来像这样:
|- Maven Root
| |- pom.xml
| |- ModuleA
| | |- pom.xml
| |- ModuleB
| | |- pom.xml
| |- ModuleX
| | |- pom.xml
| |- ModuleY
| | |- pom.xml
| |- asset1
| | |- pom.xml
| |-...
|
|- Existing-Root
|- bin
| |- moduleX.swf
| |- moduleY.swf
| |- ...
|- lib
| |- moduleA.swc
| |- moduleB.swc
| |- ...
|- src
| |- moduleA
| |- moduleB
|-...
您可能还想添加临时 pom,以便构建相关集(例如,包含所有共享模块的 share
pom)。
然后你可以:
- 使用适当的相对路径配置每个 pom,以便它可以构建其源代码。
- 配置 maven-dependency-plugin 以将
Embed
资源解压到 target/flex/resources - 使用build-helper-maven-plugin将 target/flex/resources 设置为资源位置(注意这可能实际上不起作用,因为插件期望嵌入资源位于 src/main/resources 中)
- 定义模块之间适当的依赖关系。
- 使用maven-antrun-plugin将最终工件复制到现有的 bin 目录(如果您尝试通过设置 project.build.outputDirectory 使用相同的输出目录,但随后清除一个模块将破坏其他构建)。
这是一个示例配置,用于实现其中一个 poms 的这些步骤:
<build>
<!--configure the source and test sources to point to the existing structure-->
<sourceDirectory>
${baseDir}/../../Existing-Root/test/${project.artifactId}
</sourceDirectory>
<testSourceDirectory>
${baseDir}/../../Existing-Root/src/${project.artifactId}
</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<!--unpack asset1 to target/flex/resources,
define any additional artifacts for other shares-->
<artifactItem>
<groupId>my.group.id</groupId>
<artifactId>asset1</artifactId>
<version>1.0.0</version>
<type>swf</type>
</artifactItem>
</artifactItems>
<outputDirectory>
${project.build.directory}/flex/resources
</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!--add target/flex/resources as a resource location-->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>
${project.build.directory}/flex/resources
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>pre-integration-test</phase>
<configuration>
<tasks>
<!--copy the final artifact to the module's bin directory-->
<copy
file="${project.artifactId}-${project.version}.${project.packaging}"
todir="${baseDir}/../../Existing-Root/bin/${project.artifactId}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
关于apache-flex - 具有 Flex4 设置的复杂 Maven2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1482793/