Tôi hiện đang xem xét thay thế môi trường xây dựng rất độc quyền của chúng tôi bằng Maven. Các giải pháp hiện tại là một phát triển nội bộ cho xây dựng trung tâm, và để phát triển cục bộ dễ dàng hơn tôi biên dịch bên trong Eclipse/Flex IDE và có một kịch bản ANT sao chép tất cả mọi thứ lại với thư mục Apache cục bộ của tôi (tức là tập tin kiến của tôi không thực hiện đầy đủ và cũng dựa vào việc có sẵn tất cả các dự án tại địa phương).Sử dụng Maven để xây dựng dự án Flex phức tạp
Chúng tôi đang sử dụng Eclipse 3.6.1 (Helios) với Plugin Flash Builder (tức là Flex4), nhắm mục tiêu Flex SDK 3.5 (FlashPlayer 10.0) với một số dự án cả dự án thư viện .swc và mô-đun .swf được tải trong thời gian chạy bao gồm cả tài nguyên cho mỗi. Chúng tôi cũng sử dụng các thư viện chia sẻ liên kết/thời gian chạy bên ngoài (với một sharedlibraries.swf lớn có mọi thứ bên trong, tức là không cần phải có các tệp .swc trong triển khai). Tôi đã cài đặt Maven 3.0.2, sử dụng Sonatypes flexmojos-maven-plugin 3.7.1 (vì nó có vẻ hoạt động nhiều hơn so với một từ Servebox). Tôi đã tạo các tệp pom theo cách thủ công cho mỗi dự án Eclipse, để đảm bảo rằng mọi thứ hoạt động và việc tích hợp Eclipse-Maven dường như thiếu sự hỗ trợ Flex. Tôi đã xác định các tham số biên dịch và phụ thuộc thích hợp để tất cả các dự án riêng lẻ biên dịch chính xác - tức là các tệp .swf kết quả tạo ra một phiên bản làm việc của ứng dụng của chúng tôi. Tôi cũng đọc "Maven by Example" cuốn sách từ Sonatype và nhìn vào "Maven: The Complete Reference" của họ, trong khi làm rất nhiều googling song song.
Điều tôi đang gặp phải là việc lắp ráp dự án cuối cùng của tôi, cũng như với các hiện vật bổ sung (bảng định kiểu). Tôi không hoàn toàn hiểu "cách Maven" và cũng nghi ngờ rằng Maven được thiết kế rất nhiều cho Java, do đó để lại cho tôi một chút trong tự nhiên với các dự án Flex của tôi.
cấu trúc cơ bản của các dự án của tôi:
- thư viện bên ngoài: Tôi đã thêm những người có cài đặt: cài đặt file để kho của tôi, không có vấn đề ở đây
- dự án thư viện riêng: họ từng sản xuất một .swc vật phẩm có thể được tiêu thụ trong các dự án khác, với việc xử lý phụ thuộc Maven hoạt động chính xác, không có vấn đề gì ở đây
- dự án mô-đun swf của riêng mình: ứng dụng của chúng tôi tải các tệp swf tại thời gian chạy, trong đó có một số tài nguyên bổ sung cần thiết (tệp stylesheet.swf, được bản địa hóa chuỗi như tệp .xlf riêng lẻ, tệp cấu hình, v.v.). Đó là những gì tôi đang đấu tranh với.
Layout của dự án swf của tôi:
- bin-debug/ sử dụng bởi IDE xây dựng, không được sử dụng/bỏ qua bởi Maven xây dựng
- src/ nguồn Flex (.as và .mxml tệp)
- mục tiêu/ Thư mục đích Maven
- WebContent/ một thư mục có các tập tin phụ cần được sao chép tới tạo phẩm đích (thư mục hoặc tệp zip) đúng nguyên văn, cùng với biểu tượng .swf
- kiểu/ Tệp .css cần được biên dịch thành tệp .swf stylesheet, đó là các tạo phẩm bổ sung (một cho mỗi .css, cho các chủ đề khác nhau) cho swf dự án chính và WebContent/content
Tôi đang sử dụng phân cấp phẳng để làm việc trong Eclipse, tức là tệp pom chính của tôi được đặt trong một thư mục là anh chị em cho tất cả các thư mục dự án.Ví dụ:
project_swf/src/...
project_swf/WebContent/assets/labels.xlf
project_swf/WebContent/config/config.xml
project_swf/pom.xml
lib_swc/src/...
lib_swc/pom.xml
master_build/pom.xml
master_build/swf-assembly.xml
tôi đã quản lý để tạo ra một 'bậc thầy xây dựng' xây dựng các dự án SWC và swf của tôi sử dụng bậc thầy này 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>
<name>Dragon Master Build</name>
<description>This project can be used to build and package the client application</description>
<properties>
<!-- this needs to be the same as the groupId tag, which unfortunately cannot be accessed directly using ${} notation -->
<group-id>de.zefiro.maven.example</group-id>
<!-- parameter to plugin swf files, shown as plugin 'Build Number' in client -->
<!-- TODO should be a build number on central system -->
<zefiro.plugin.buildno>local_dev_mvn</zefiro.plugin.buildno>
<!-- build all SWF files (except sharedlibraries.swf) with external references (Note: Flexmojo abuses the 'scope' concept here, but there is currently no better way) -->
<zefiro.swf.scope>external</zefiro.swf.scope>
</properties>
<groupId>de.zefiro.maven.example</groupId>
<artifactId>full_build</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.7.1</version>
<extensions>true</extensions>
<!-- We need to compile with Flex SDK 3.5 -->
<dependencies><dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>3.5.0.12683</version>
<type>pom</type>
</dependency></dependencies>
<!-- configuration for the Flex compilation -->
<configuration>
<targetPlayer>10.0.0</targetPlayer>
<incremental>false</incremental>
<debug>false</debug>
<runtimeLocales></runtimeLocales>
<locale>en_US</locale>
<optimize>true</optimize>
<showWarnings>true</showWarnings>
<strict>true</strict>
<useNetwork>true</useNetwork>
<allowSourcePathOverlap>true</allowSourcePathOverlap>
<definesDeclaration>
<property>
<name>ZEFIRO::META_INFO</name>
<value>"buildno=${zefiro.plugin.buildno}"</value>
</property>
</definesDeclaration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>3.5.0.12683</version>
<type>pom</type>
<exclusions>
<!-- make sure to exclude the default 'playerglobal' transitive dependency (which would be version 9 for SDK 3.5, however, we want version 10) -->
<exclusion>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<!-- this artifact version must match the flex SDK version used in this project -->
<version>3.5.0.12683</version>
<!-- the classifier specifies the target flash player major version (default is 9 for SDK 3.5) -->
<classifier>10</classifier>
<type>swc</type>
</dependency>
[... some more dependencies needed by all projects ...]
</dependencies>
<modules>
<module>../lib_swc</module>
<module>../project_swf</module>
[... calls all my projects ...]
</modules>
</project>
Sau đó tôi có thể biên dịch dự án thư viện SWC của tôi với POM đơn giản này:
<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>Sample library project</name>
<artifactId>lib_swc</artifactId>
<packaging>swc</packaging>
<dependencies>
<dependency>
<groupId>${group-id}</groupId>
<artifactId>some_other_library</artifactId>
<version>${project.version}</version> <!-- I should probably look into dependency/versioning as well, but for now this works -->
<!-- Note: no 'Scope' here, swc files will be build "merged into code"-style. Needed as transitive dependencies don't work with Maven/Flex - we use 'external' scope for the final swf projects dependencies -->
<type>swc</type>
</dependency>
</dependencies>
</project>
Và swf tôi dự án với POM này:
<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>Sample SWF module</name>
<artifactId>project_swf</artifactId>
<packaging>swf</packaging>
<build>
<!-- This name needs to be exactly specified, as the runtime will load it as it's specified in the configuration xml -->
<finalName>SampleProjectModule1</finalName>
<!-- define the master source file, it's picked up for some projects automatically and must be specified for others. Inherits compiler parameters from parent. -->
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<sourceFile>project_swf_master_file.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>
Đó là sự hiểu biết của tôi rằng mỗi file POM tạo ra một tập tin mục tiêu (chỉ định với các thẻ bao bì) và rằng khi sử dụng Flex Mojo này cần phải được định dạng swf hoặc SWC. Tôi dường như không thể xác định nhiều mục tiêu ở đây và cũng phải vật lộn để lấy các tệp tài nguyên của mình (Tài nguyên bản sao Flex sao chép trình bao bọc html mà tôi không cần (đối với mỗi dự án), thẻ tài nguyên bình thường sao chép tài nguyên, nhưng không không gói chúng). Hiện tại phiên bản làm việc hiện tại của tôi là chỉ định một bộ mô tả lắp ráp của riêng nó, gói các tệp .swf đích của tôi cùng với thư mục WebContent/vào một tệp nén. Maven hỗ trợ các tệp jar/war/bin, nhưng những điều đó dường như mong đợi các điều kiện nhất định là đúng, không áp dụng cho các dự án Flex của tôi (ví dụ: tôi không có web.xml)
swf- assembly.xml:
<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>WebContent</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- Take the base 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>
<!-- add the WebContent folder -->
<fileSet>
<directory>FCPContent</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
Bây giờ tôi đã có thư mục đích với cả hai tập tin .swf một mình và một file zip có chứa tập tin .swf của tôi cùng với WebContent tôi/nguồn lực. Nó cũng được đặt trong kho lưu trữ Nexus khi gọi 'mvn install', vì vậy đây trông giống như một bước tiến tốt. Mặc dù tôi rất vui khi làm điều đó hoàn toàn khác nếu tốt hơn, vì mục tiêu cuối cùng của tôi là có một thư mục (hoặc tệp zip/war chứa nó) với một số tệp tĩnh trong đó (trình bao bọc html của chúng tôi và trình nạp tệp swf + configuration.xml) và cho mỗi dự án swf của chúng tôi (các mô-đun chúng tôi tải khi chạy) một thư mục chứa các tệp .swf và WebContent/resources - tức là nội dung của các tệp zip tôi hiện có thể tạo cho từng dự án.
index.html
loader.swf
config.xml
project_swf/SampleProjectModule1.swf
project_swf/assets/labels.xlf
project_swf/config/config.xml
project2_swf/module2.swf
project2_swf/cool_colors_stylesheet.swf
Vì vậy, câu hỏi của tôi sẽ là: cách xác định dự án tổng thể Maven tạo phiên bản cuối cùng theo định dạng này? Nếu không có cách nào khác, một tệp ANT hoạt động có thể chấp nhận được, mặc dù tôi đã đọc rằng Maven đã thúc giục chúng ta tránh xa những lỗi đó :)
Tôi cũng cần biên dịch các tệp định kiểu stylesheet sau đó là các tạo phẩm bổ sung cho dự án swf. Tôi sẽ đăng một câu hỏi riêng cho việc này.