好的,我认为以下内容可能会满足您的需求。这种方法的缺点是在执行后续构建时,每次部署之间会有一个间隔。这可以接受吗?
在每个项目中定义一个具有相同名称的配置文件(例如“发布”)。在该配置文件中,您可以定义配置以使用 antrun-plugin 通过 FTP 传送文件(见下文)。
在父项目中,您将拥有一个 modules 元素,将每个项目定义为一个模块。如果您运行mvn install -P publish,每个项目将在启用发布配置文件的情况下依次构建,并在安装阶段将最终工件发布到目标。如果您需要部署额外的文件,请相应地修改包含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>