我目前正在修改POM以便以及编译它创建可以在目标服务器上轻松运行部署包的代码。
父POM调用依次构建的许多模块。为了将这些模块中的所有构建文物都放到已知的位置,我添加了一个名为“分布”的新模块以及它自己的POM。这个POM拥有Maven Assembly和Maven AntRun的插件。
Assembly插件钩入“一揽子”的生命周期:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembler.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
汇编XML同时使用moduleSets和文件集带来必需的文件到输出目录。我使用'useAllReactorProjects'标志让系统获取所有需要包含在部署包中的构建'war'文件。
<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>bin</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.example.fire:fire-apis-admin-pack-sesame-rest</include>
<include>com.example.fire:fire-apis-asset-pack-sesame-rest</include>
<include>com.example.fire:fire-apis-event-pack-sesame-rest</include>
<include>com.example.fire:fire-apis-geonames-pack-sesame-rest</include>
<include>com.example.fire:fire-apis-stuff-pack-sesame-rest</include>
</includes>
<binaries>
<outputDirectory>modules</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
<!-- Include the Deployment code -->
<fileSets>
<fileSet>
<directory>${almfx.path}</directory>
<outputDirectory>almfx</outputDirectory>
<includes>
<include>**</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
这一切运作良好,我可以看到在输出目录中的文件,当我运行mvn package
。
接下来就是我遇到问题的地方。我需要做的包装上更多的工作,所以我试图钩到“预集成测试”的生命周期:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>pre-integration-test</phase>
<configuration>
<target>
<echo message="Calling ANT from Maven" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
正如你可以看到我在尝试使用antrun插件来完成这项工作。我现在只是在做一个简单的测试,那就是将某些东西输出到屏幕上。
现在,当我运行mvn pre-integration-test
'包'阶段与以前一样工作,我看到所有输出。但是,当涉及到“预集成测试”阶段时,我会遇到缺失伪像的问题。
现在我认为,由于系统已经构建了代码,并且它已经全部在本地,所以它不会寻找任何其他的工件来引入它正在寻找的工件是在其中一个模块已编译,因此不在本地或远程存储库中。
因为我只想在'包'阶段的输出上做一些工作,所以我不需要下载任何东西,但我不知道我该如何实现这一点。我一直在环顾网络,试图找出如何解决这个问题,但所有的例子都显示出类似于我正在做的事情。
如果任何人有任何我在做什么错误的指针,请让我知道。 我希望我已经提供了所需的所有信息,但请让我知道如果您需要了,我会很乐意提供。
在此先感谢非常多,
罗素
更新时间:2012-02-08 1450
安德鲁斯的建议后,我修改了分配POM稍微所以该AntRun插件是部分相同的“包装”阶段。由于AntRun插件没有“单个”作为目标,因此我无法将其添加到相同的目标中,因此我将其保留为运行状态。
不幸的是我看到了系统试图从它已经构建的存储库中下载某些东西的相同问题。错误的排序我得到的是:
Downloading: http://nexus/nexus/content/groups/public/com/example/fire/fire-apis/latest-SNAPSH
OT/fire-apis-latest-20120208.061113-108.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.example.fire:fire-apis:jar:latest-SNAPSHOT
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.example.fire -DartifactId=fire-apis -Dversion=latest-20120208.0611
13-108 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.example.fire -DartifactId=fire-apis -Dversion=latest-20120208.061113
-108 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.example.fire:distribution:pom:latest-SNAPSHOT
2) com.example.fire:fire-apis:jar:latest-SNAPSHOT
----------
1 required artifact is missing.
for artifact:
com.example.fire:distribution:pom:latest-SNAPSHOT
from the specified remote repositories:
public-mirror (http://nexus/nexus/content/groups/public)
我难倒这个,因为我认为这将是做到这一点的方式。我知道我错过了一些东西。如果有帮助,我可以发布日志,但它会很大。
更新:2012-02-09 1130
使人们有什么,我试图做的我已经发布了一些信息到引擎收录更好的视野。
父POM - http://pastebin.com/adpnZVe1
分配模块POM - http://pastebin.com/bycHcqgk
Maven的调试日志 - http://pastebin.com/dDBV5uNM
这是实现这一涉及到AntRun部主日志文件的末尾片段。 (主日志文件超过11Mb !!)
使用useAllReactorProjects
标志来做所有这些包装我按照此页面的示例http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html。
谢谢。
很好听的问题得到解决=)在大部分我们的项目,我们有永远是最后的,取决于模块的其他“一揽子”实用模块。这种方法似乎工作得很好。 – 2012-02-10 10:35:05