带有 Flex4 设置的复杂 Maven2

发布于 2024-08-06 08:27:14 字数 1147 浏览 10 评论 0原文

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

我已经成功使用 Maven2 和 Flex4 创建了一个单模块项目(我正在使用 Sonatype FlexMojos 插件及其位于 http://repository.sonatype.org/内容/组/flexgroup/)。当涉及到制作这个多模块时,我真的开始遇到麻烦了......

我们的项目组织如下:

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微凉徒眸意 2024-08-13 08:27:14

如果您确定要迁移到 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>

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>
一张白纸 2024-08-13 08:27:14

多模块项目应该如下所示:

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

A multi-module project should look like this

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

Having multiple sources in a single project is fine if you plan on building a single artifact, but Maven does not cooperate if you are trying to build multiple artifacts from multiple sources in a single project.

If you can not move the source tree around; create a multi-module pom hierarchy in the current structure and edit the new child-poms to point their src and test directories to the current source hierarchy src and test directories.

You can have the output folders all point to the same folder as well.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文