2009-09-27 87 views
3

我一直在努力让Maven2与我合作,并想知道如果有人有任何想法如何得到这个工作....我正在一个Flash项目,我们正在考虑将我们的混合Flex4/FlashCS4转换为纯Flex4解决方案。我们希望使用Maven2构建系统,这样我们的开发人员就不必在他们的机器上手动下载,安装和配置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]”标签引用的内容)存在于“共享”下。我已经看过关于项目继承和聚合的参考资料,但似乎找不到任何可以让我们保留现有项目目录结构的内容。我们希望这种迁移尽可能快速,无痛且不中断。如果有人能想出如何创建一个允许我们保留当前基础架构的“pom.xml”文件,我将非常感激。

回答

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

您可能还需要增加临时劲歌这样你就可以建立相关的集(例如包含所有共享模块share POM)。

,那么你可以:

  • 配置每个POM具有适当的相对路径,以便它可以建立自己的来源。
  • 配置Maven的依赖,插件解压Embed资源到目标/柔性/资源
  • 使用build-helper-maven-plugin设定目标/柔性/资源作为一个资源位置(注意,这可能不实际工作,因为插件预计嵌入资源在src/main/resources中)
  • 定义模块之间的适当依赖关系。
  • 使用maven-antrun-plugin将最终构件复制到现有的bin目录(如果您尝试通过设置project.build.outputDirectory来使用相同的输出目录,但随后清理一个模块将会打断其他构建)。

下面是一个例子的配置来实现这些步骤的劲歌之一:

<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> 
+0

谢谢,这是一个非常详细的帖子。我期待着尝试它。 –

0

多模块项目应该是这样的

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

有单个项目中的多个来源是好的,如果你打算建立一个单一的神器,但是如果你正在试图建立多Maven的不配合来自单个项目中多个来源的工件。

如果你不能移动源代码树;在当前结构中创建一个多模块pom层次结构,并编辑新的子poms以将它们的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 
+0

这就是我从文档中获得的印象......我希望有可能是某种变通方法。 –