复杂的Maven2与Flex4设置 [英] Complex Maven2 with Flex4 Setup

查看:212
本文介绍了复杂的Maven2与Flex4设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我已经设法创建一个使用Maven2和Flex4的单模块项目(我正在使用Sonatype FlexMojos插件及其Maven2存储库,位于 http://repository.sonatype.org/content/groups/flexgroup/ )。

我们的项目是这样组织的:

 
| - bin
| | - moduleX.swf
| | - moduleY.swf
| | - ...
| - lib
| | - moduleA.swc
| | - moduleB.swc
| | - ...
| - src
| | - moduleA
| | - moduleB
| | - ...
| - 测试
| | - moduleA
| | - moduleB
| | - ...
| - 分享
| | - asset1
| | - asset2
| | - ...
| - ...

基本上,我们每个模块的源代码位于src / < modulename> /及其测试源位于test /< modulename> /下,生成的SWF文件被放置在bin中,生成的SWC文件被放置在lib中。我们的资产(我们希望能够使用@Embed或[Embed]标签来引用的东西)生活在共享下。我已经看过项目继承和聚合的参考资料,但似乎无法找到任何可以让我们保留现有项目目录结构的东西。我们希望这种迁移尽可能快速,无痛且不中断。我真的很感激,如果有人可以找出如何创建一个pom.xml文件,使我们能够保持我们目前的基础设施。

>

如果您确定要转移到Maven 2,那么修改项目结构将会为您节省很多痛苦,因此每个模块都包含自己的源代码和测试,并遵循Maven惯例。



如果你真的无法做到这一点,你可以创建一个并行模块层次结构,并配置每个模块的相对路径指向你现有的结构。结构可能会看起来像这样:

  |  -  Maven Root 
| | - pom.xml
| | - ModuleA
| | | - pom.xml
| | - ModuleB
| | | - pom.xml
| | - ModuleX
| | | - pom.xml
| | - ModuleY
| | | - pom.xml
| | - asset1
| | | - pom.xml
| | -...
|
| - 现有根
| - bin
| | - moduleX.swf
| | - moduleY.swf
| | - ...
| - lib
| | - moduleA.swc
| | - moduleB.swc
| | - ...
| - src
| | - moduleA
| | - moduleB
| -...

您可能还需要添加临时poms你可以构建相关的集合(例如,包含所有共享模块的 share pom)。

然后你可以:


  • 为每个pom配置合适的相对路径,以便构建源代码。 -dependency-plugin解开嵌入资源到target / flex / resources
  • 使用 build-helper-maven-plugin 将target / flex / resources设置为资源位置,因为插件期望Embed资源位于src / main / resources中)
  • 定义模块之间的适当依赖关系。
  • 使用 maven-antrun-plugin 将最终的工件复制到existi ng bin目录(如果您尝试通过设置project.build.outputDirectory来使用相同的输出目录,但是其中一个模块的清除将会打破其他的构建)。


    以下是为其中一个poms实现这些步骤的示例配置:

     < build> 
    <! - 将来源和测试来源配置为指向现有结构 - >
    < 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>
    <执行>
    < id>解包< / id>
    <阶段>生成资源< /阶段>
    <目标>
    < goal>解包< / goal>
    < /目标>
    <配置>
    < artifactItems>
    <! - 将资产1解包为目标/弹性/资源,
    定义其他股份的任何其他工件 - >
    < 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>
    < /执行>
    < /执行次数>
    < / plugin>
    < plugin>
    <! - 将target / flex / resources添加为资源位置 - >
    < groupId> org.codehaus.mojo< / groupId>
    < artifactId> build-helper-maven-plugin< / artifactId>
    < version> 1.3< / version>
    < executions>
    <执行>
    < id> add-resource< / id>
    <阶段>生成资源< /阶段>
    <目标>
    < goal> add-resources< / goal>
    < /目标>
    <配置>
    <资源>
    < resource>
    <目录>
    $ {project.build.directory} / flex / resources
    < / directory>
    < / resource>
    < /资源>
    < / configuration>
    < /执行>
    < /执行次数>
    < / plugin>
    < plugin>
    < artifactId> maven-antrun-plugin< / artifactId>
    < executions>
    <执行>
    <阶段>预积分测试< /阶段>
    <配置>
    <任务>
    <! - 将最终的工件复制到模块的bin目录 - >
    < copy
    file =$ {project.artifactId} - $ {project.version}。$ {project.packaging}
    todir =$ {baseDir} /../ ../Existing-Root/bin/${project.artifactId}\"/>
    < /任务>
    < / configuration>
    <目标>
    < goal>运行< / goal>
    < /目标>
    < /执行>
    < /执行次数>
    < / plugin>
    < / plugins>
    ...
    < / build>


    I have been struggling to get Maven2 to cooperate with me, and was wondering if anyone out there had any ideas on how to get this working.... I am working on a Flash project, and we are considering switching from our hybrid Flex4/FlashCS4 to a pure Flex4 solution. We would like to use the Maven2 build system, so that our developers do not have to manually download, install, and configure Flex4 on their machines.

    I have managed to create a single-module project using Maven2 with Flex4 (I am using the Sonatype FlexMojos Plugin and their Maven2 repository located at http://repository.sonatype.org/content/groups/flexgroup/). I really start running into trouble when it comes to making this multimodule....

    Our project is organized as follows:

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

    Basically, each of our modules has its sources located under "src/<modulename>/" and its test sources located under "test/<modulename>/", with generated SWF files being placed in "bin" and generated SWC files being placed in "lib". Our assets (things that we would like to be able to reference using the "@Embed" or "[Embed]" tags) live under "share". I have looked at the references on project inheritance and aggregation, but can't seem to find anything that would allow us to keep our existing project directory structure. We would like this migration to be as quick, painless, and non-disruptive as possible. I would really appreciate it if anyone can figure out how to create a "pom.xml" file that allows us to keep our current infrastructure.

    解决方案

    If you are certain about moving to Maven 2, it will save you a lot of pain to modify the project structure so each module contains its own sources and tests and follows the Maven conventions.

    If you really can't do that, you can create a parallel module hierarchy, and configure each module with relative paths pointing back to your existing structure. The structure could end up looking something like this:

    |- 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
        |-...
    

    You may also want to add interim poms so you can build related sets (e.g. a share pom containing all the share modules).

    You could then:

    • configure each pom with the appropriate relative paths so it can build its sources.
    • configure the maven-dependency-plugin to unpack Embed resources into target/flex/resources
    • use the build-helper-maven-plugin to set target/flex/resources as a resource location (note this may not actually work, as the plugin expects Embed resources to be in src/main/resources)
    • define the appropriate dependencies between modules.
    • use the maven-antrun-plugin to copy the final artifacts to the existing bin directory (if you attempt to use the same output directory by setting project.build.outputDirectory, but then a clean of one module will clobber other builds).

    Here is an example configuration to achieve those steps for one of the 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>
    

    这篇关于复杂的Maven2与Flex4设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆