我没有找到从同一个 POM 文件创建多个工件的方法,甚至没有多次运行 flexmojo 编译目标(即使与执行标签绑定,Maven 也会抱怨)。所以我发现最好的方法是使用与我的整个项目非常相似的解决方案,我已经描述了in this question, including my solution,我建议阅读它,因为我会以此为基础。我曾希望在这里有一个不那么骇人听闻的解决方案,使用这种多项目方法对我来说似乎有点脏。这也是我拆分问题的原因,这反过来又让我有幸被杰夫·阿特伍德本人注意到:)
我只想为我的插件使用一个 Eclipse 项目,但需要多个文件夹来使用多个 POM。我的文件夹结构如下所示:
colored_plugin/src/colored_plugin_main.as
colored_plugin/src/green.css
colored_plugin/src/...
colored_plugin/src/assets/rainbow.jpg <- will be embedded into stylesheet swf file
colored_plugin/WebContent/assets/labels.xlf
colored_plugin/WebContent/config/config.xlf
colored_plugin/POMs/assembly/pom.xml
colored_plugin/POMs/plugin/pom.xml
colored_plugin/POMs/style1/pom.xml
colored_plugin/pom.xml
master_build/pom.xml
master_build/swf-assembly.xml
master_build/css-assembly.xml
master_build/plugin-assembly.xml
master_build/assembly/pom.xml
master_build/assembly/final-asembly.xml
我使用 master_build 文件夹作为中心位置来存储我的简单 swf 项目的 swf 程序集文件,因此我将包含样式表的插件的程序集描述符放在同一位置。
编译插件的 POM (POMs/plugin/pom.xml) 与简单的 swf 项目之一非常相似(请参阅其他问题):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.zefiro.maven.example</groupId>
<artifactId>colored_plugin_internal</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<name>Colored Plugin (Plugin Executeable)</name>
<artifactId>${project.parent.artifactId}_swf</artifactId>
<packaging>swf</packaging>
<build>
<sourceDirectory>../../src</sourceDirectory>
<!-- This name needs to be exactly specified, as the runtime will load it as it's specified in the configuration xml -->
<finalName>SampleProjectModuleColored</finalName>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<sourceFile>colored_plugin_main.as</sourceFile>
</configuration>
</plugin>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>../../../master_build/swf-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>WebContent-packaging</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${group-id}</groupId>
<artifactId>project_swc</artifactId>
<version>${project.version}</version>
<scope>${zefiro.swf.scope}</scope> <!-- tell Flex Mojo that we want to compile using runtime shared libraries (rsl) -->
<type>swc</type>
</dependency>
[...]
</dependencies>
</project>
样式表的 POM 是一个几乎相同的版本:.css 文件被指定为源,这里不需要依赖项(至少在我的情况下),但它仍然需要打包以便我以后可以为程序集引用(并重新打包)它。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.zefiro.maven.example</groupId>
<artifactId>colored_plugin_internal</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<name>Colored Plugin (Stylesheet 'Green')</name>
<artifactId>${project.parent.artifactId}_css_green</artifactId>
<packaging>swf</packaging>
<build>
<sourceDirectory>../../src</sourceDirectory>
<finalName>style_green</finalName>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<sourceFile>green.css</sourceFile>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>../../../master_build/css-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>WebContent-packaging</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
程序集描述符也是简化版,只是打包了swf文件。我不确定它是否需要,也许可以直接使用默认的 Maven 工件来完成组装,但对我来说,就像在其他所有项目中一样进行组装是最简单的。
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>Stylesheet</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- Take the stylesheet swf artifact (only, not the other stuff which is generated there) -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.swf</include>
</includes>
</fileSet>
</fileSets>
</assembly>
组装项目有这个POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.zefiro.maven.example</groupId>
<artifactId>colored_plugin_internal</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<name>Colored Plugin (Assembly)</name>
<artifactId>colored_plugin</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>../../../master_build/plugin-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>Plugin_assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${group-id}</groupId>
<artifactId>${project.parent.artifactId}_swf</artifactId>
<version>${project.version}</version>
<type>zip</type>
<classifier>WebContent</classifier>
</dependency>
<dependency>
<groupId>${group-id}</groupId>
<artifactId>${project.parent.artifactId}_css_green</artifactId>
<version>${project.version}</version>
<type>zip</type>
<classifier>Stylesheet</classifier>
</dependency>
</dependencies>
</project>
插件程序集描述符将所有这些打包在一起。它也位于中心位置,因此以通用方式编写:它从调用 POM 引用 group-id 和 artifactId 并使用我介绍的名称约定。最终项目将由程序集 POM 构建,因此我指定了“不错”的 artifactId。主项目 POM(见下文)有一个手动派生的名称,而所有其他项目(主应用程序和所有样式表)都自动派生于此并生成仅在内部使用的 Maven 工件。我有不止一个样式表,所以我真正的程序集 POM 列出了多个样式表依赖项(与本示例相反),而我的程序集描述符使用通配符将它们全部获取。
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>WebContent</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- add the WebContent folder -->
<fileSet>
<directory>../../WebContent</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<!-- add plugin main executable -->
<dependencySet>
<includes>
<include>${group-id}:${project.parent.artifactId}_swf:zip:WebContent:${project.version}</include>
</includes>
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
<outputDirectory>/</outputDirectory>
</dependencySet>
<!-- add stylesheets -->
<dependencySet>
<includes>
<include>${group-id}:${project.parent.artifactId}_css_*:zip:Stylesheet:${project.version}</include>
</includes>
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
<outputDirectory>/assets/styles</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
请注意,我对这个程序集描述符使用的 ID 与用于简单 swf 项目的 ID 相同(如我的另一个问题所示)。这使得在整个程序集插件中指定正确的工件变得更加容易,因为我可以只使用“WebContent”作为我所有项目的分类器。
最后,我项目的主要 POM 只是其他 POM 的一个小调用者:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.zefiro.maven.example</groupId>
<artifactId>full_build</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../master_build</relativePath>
</parent>
<name>Colored Plugin</name>
<artifactId>colored_plugin_internal</artifactId>
<packaging>pom</packaging>
<modules>
<module>pom/plugin</module>
<module>pom/style1</module>
<module>pom/assembly</module>
</modules>
</project>
可以通过以下方式添加新样式表:
- 将 red.css 样式表和所有随附文件添加到 src/ 目录
- 将 coloured_plugin/POMs/style1/pom.xml 复制到 colour_plugin/POMs/style2/pom.xml
- 将其作为模块添加到 coloured_plugin/pom.xm
- 将其添加到 coloured_plugin/POMs/assembly/pom.xm 作为依赖项
- 由于通配符和命名约定,程序集描述符 (/master_build/plugin-assembly.xml) 不需要更改
最终的项目工件是一个 zip 文件,由我的主程序集使用(并与其他项目合并)并包含这些文件:
SampleProjectModuleColored.swf
assets/labels.xlf
assets/styles/style_green.swf
config/config.xlf
它将存储在存储库中
de.zefiro.maven.example:colored_plugin:zip:WebContent:1.0-SNAPSHOT