好吧,我想下面可能做你的需要。这种方法的缺点是,随着后续构建的执行,每个部署之间会有间隔。这可以接受吗?
在每个项目中定义一个具有相同名称的配置文件(称为“发布”)。在该配置文件中,您可以定义配置以使用antrun-plugin通过FTP传输文件(请参见下文)。
在父项目中,您将拥有一个modules元素,将每个项目定义为一个模块。如果您运行的是mvn install -P publish
,则每个项目都将依次构建,并启用发布配置文件,并在安装阶段将最终工件发布到目标。如果您需要部署其他文件,请相应地修改include element
。
请注意FTP任务的参数已设置为属性,这样可以从命令行覆盖它们和/或从父POM继承它们。
<profiles>
<profile>
<id>publish</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<ftp action="send"
server="${ftp.host}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
depends="${ftp.depends}" verbose="${ftp.verbose}">
<fileset dir="${project.build.directory}">
<include
name="${project.build.finalName}.${project.packaging}"/>
</fileset>
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
<properties>
<ftp.host>hostname</ftp.host>
<ftp.remotedir>/opt/path/to/install</ftp.remotedir>
<ftp.userid>user</ftp.userid>
<ftp.password>mypassword</ftp.password>
<ftp.depends>yes</ftp.depends>
<ftp.verbose>no</ftp.verbose>
</properties>
</profile>
</profiles>
更新:基于您的评论:您可以使用依赖插件下载每个依赖,但家长不能对孩子的依赖性,它会在孩子前建成。这将是另一个项目。您还需要在某处提供将它们部署到哪里的信息。目前,您在各个项目中拥有目标信息,因此无法在部署人员项目中访问。
采取这种方法,您可以在新项目中定义多个配置文件,每个配件一个。每个配置文件定义一个依赖项:复制执行以获取jar和一个项目的antrun执行。常见配置(例如antrun插件的依赖关系)可以从配置文件中取出。另外请注意,如果您定义了多个配置文件,这些属性将被合并,因此您可能需要使用工件名称来限定它们,例如ftp.artifact1.host
。
<profiles>
<profile>
<id>deploy-artifact1</id>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependency</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>name.seller.rich</groupId>
<artifactId>artifact1</artifactId>
<version>1.0.0</version>
<type>jar</type>
<overWrite>false</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/deploy-staging</outputDirectory>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<ftp action="send"
server="${ftp.host}" remotedir="${ftp.remotedir}"
userid="${ftp.userid}" password="${ftp.password}"
depends="${ftp.depends}" verbose="${ftp.verbose}">
<fileset dir="${project.build.directory} includes="deploy-staging/"/>
</ftp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<properties>
<!--if the properties differ between targets, qualify them with the artifact name-->
<ftp.host>hostname</ftp.host>
<ftp.remotedir>/opt/path/to/install</ftp.remotedir>
<ftp.userid>user</ftp.userid>
<ftp.password>mypassword</ftp.password>
<ftp.depends>yes</ftp.depends>
<ftp.verbose>no</ftp.verbose>
</properties>
</profile>
</profiles>
哈哈。我希望我和我的公司的Maven“卡在一起”。 – SingleShot 2009-09-10 15:27:28
我的意思并不是贬义:) – Bostone 2009-09-10 15:28:55
我不明白“子项目级提供的目的地”是什么意思。你是否将所有文件传送到每个目的地? – 2009-09-10 15:31:13