复杂的Maven2和Flex4设置

3

我一直在努力让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/<modulename>/”,测试源代码位于“test/<modulename>/”,生成的SWF文件位于“bin”,生成的SWC文件位于“lib”。我们的资源(希望能够使用“@Embed”或“[Embed]”标签引用的东西)位于“share”下。我已经查看了关于项目继承和聚合的参考资料,但似乎找不到任何可以让我们保留现有项目目录结构的方法。我们希望这个迁移尽可能快速、无痛、不会造成任何干扰。如果有人能够想出如何创建一个“pom.xml”文件,使我们能够保持当前的基础设施,我将不胜感激。

2个回答

3
如果您确定要转移到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设置为资源位置(请注意,这可能无法正常工作,因为插件希望Embed资源在src/main/resources中)。 - 定义模块之间的适当依赖关系。 - 使用maven-antrun-plugin将最终产物复制到现有的bin目录中(如果您尝试通过设置project.build.outputDirectory使用相同的输出目录,则一个模块的清理将破坏其他构建)。
以下是实现上述步骤的一个pom文件的示例配置:
<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>

谢谢,这是一篇非常详细的帖子。我期待着尝试它。 - Michael Aaron Safyan

0
一个多模块项目应该长成这样。
Root
 |- Module a
 |  |- src
 |- Module b
 |  |- src
 |- Module c
 |  |- src

如果您计划构建单个工件,则在单个项目中具有多个源是可以的,但如果您尝试从多个源构建多个工件,则Maven将不予合作。

如果您无法移动源树,请在当前结构中创建多模块POM层次结构,并编辑新的子POM以将其src和test目录指向当前源层次结构的src和test目录。

您还可以将输出文件夹全部指向同一个文件夹。

root
 |- ModuleA
 |  |- pom.xml, src points to root/src/moduleA
 |- ModuleB
 |  |- pom.xml, src points to root/src/moduleB
 |- src
 |  |- moduleA
 |  |- moduleB
 |  |- ...
 |- test
 |  |- moduleA
 |  |- moduleB

这是我从文档中得到的印象...我希望可能有某种解决方法。 - Michael Aaron Safyan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接