代码之家  ›  专栏  ›  技术社区  ›  Michael Aaron Safyan

带有Flex4设置的复杂Maven2

  •  3
  • Michael Aaron Safyan  · 技术社区  · 16 年前

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

    我已经使用Maven2和Flex4创建了一个单模块项目(我使用的是Sonatype FlexMojos插件及其位于 http://repository.sonatype.org/content/groups/flexgroup/ ). 我真的开始遇到麻烦,当涉及到做这个多模块。。。。

     |- bin
     |  |- moduleX.swf
     |  |- moduleY.swf
     |  |- ...
     |- lib
     |  |- moduleA.swc
     |  |- moduleB.swc
     |  |- ...
     |- src
     |  |- moduleA
     |  |- moduleB
     |  |- ...
     |- test
     |  |- moduleA
     |  |- moduleB
     |  |- ...
     |- share
     |  |- asset1
     |  |- asset2
     |  |- ...
     |- ...
    

    基本上,我们的每个模块都有其源位于“src/<模块名称>/“其测试源位于“测试/<modulename>/“,生成的SWF文件放在“bin”中,生成的SWC文件放在“lib”中。我们的资产(我们希望能够使用“@Embed”或“[Embed]”标记引用的东西)位于“共享”下。我查看了有关项目继承和聚合的参考资料,但似乎找不到任何可以让我们保持现有项目目录结构的内容。我们希望这次迁移尽可能快、无痛、无中断。如果有人能想出如何创建一个“pom.xml”文件,使我们能够保持现有的基础设施,我将不胜感激。

    2 回复  |  直到 16 年前
        1
  •  3
  •   Rich Seller    16 年前

    如果您确定要迁移到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,以便它可以构建其源。
    • Embed 将资源分为target/flex/resources
    • build-helper-maven-plugin 将target/flex/resources设置为资源位置(注意,这可能实际上不起作用,因为插件希望嵌入的资源位于src/main/resources中)
    • 定义模块之间的适当依赖关系。
    • 使用 maven-antrun-plugin

    以下是为其中一个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
  •  0
  •   sal    16 年前

    Root
     |- Module a
     |  |- src
     |- Module b
     |  |- src
     |- Module c
     |  |- src
    

    如果您计划构建单个工件,那么在单个项目中拥有多个源是可以的,但是如果您试图在单个项目中从多个源构建多个工件,Maven不会合作。

    如果无法移动源树,请执行以下操作:;在当前结构中创建多模块pom层次结构,并编辑新的子pom以将其src和测试目录指向当前源层次结构src和测试目录。

    您也可以让输出文件夹都指向同一文件夹。

    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
    
    推荐文章