【问题标题】:Complex Maven2 with Flex4 Setup具有 Flex4 设置的复杂 Maven2
【发布时间】:2010-12-01 18:04:12
【问题描述】:

我一直在努力让 Maven2 与我合作,并且想知道是否有人对如何使其工作有任何想法......我正在从事一个 Flash 项目,我们正在考虑从我们的混合 Flex4/FlashCS4 到纯 Flex4 解决方案。我们希望使用 Maven2 构建系统,这样我们的开发人员就不必在他们的机器上手动下载、安装和配置 Flex4。

我已经设法使用带有 Flex4 的 Maven2 创建了一个单模块项目(我正在使用 Sonatype FlexMojos 插件及其位于 http://repository.sonatype.org/content/groups/flexgroup/ 的 Maven2 存储库)。在制作这个多模块时,我真的开始遇到麻烦了......

我们的项目组织如下:

|- 斌 | |- 模块X.swf | |- 模块Y.swf | |- ... |- 库 | |- 模块A.swc | |- 模块B.swc | |- ... |- 源 | |- 模块A | |- 模块B | |- ... |- 测试 | |- 模块A | |- 模块B | |- ... |- 分享 | |- 资产1 | |- 资产2 | |- ... |- ...

基本上,我们的每个模块的源代码位于“src//”下,其测试源代码位于“test//”下,生成的 SWF 文件放置在“bin”中并生成 SWC文件被放置在“lib”中。我们的资产(我们希望能够使用“@Embed”或“[Embed]”标签引用的东西)位于“share”下。我查看了有关项目继承和聚合的参考资料,但似乎找不到任何可以让我们保留现有项目目录结构的东西。我们希望此迁移尽可能快速、轻松且无中断。如果有人能弄清楚如何创建一个“pom.xml”文件来让我们保留当前的基础设施,我将不胜感激。

【问题讨论】:

    标签: apache-flex maven-2 gumbo flex-mojos sonatype


    【解决方案1】:

    如果您确定要迁移到 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 来使用相同的输出目录,但清除一个模块会破坏其他构建)。

    这是一个示例配置,用于实现其中一个 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>
    

    【讨论】:

    • 谢谢,那是一篇非常详细的帖子。我期待着尝试。
    【解决方案2】:

    一个多模块项目应该是这样的

    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
    

    【讨论】:

    • 这是我从文档中得到的印象......我希望可能有某种解决方法。
    猜你喜欢
    • 2018-01-04
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2011-12-29
    • 2011-03-12
    • 2021-05-14
    • 1970-01-01
    • 2013-01-22
    相关资源
    最近更新 更多