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