Bos*_*one 21 deployment maven-2
我有使用Maven的4个嵌套子项目的项目任务:
文件不是Java - 主要是各种脚本和HTML
我正在查看各种插件来帮助完成任务:汇编,依赖,antrun,解压缩.依赖性看起来很有希望,但我不仅需要解压缩依赖jar,还要解压缩(子)项目内容.此外,由于我无法真正将操作紧缩到Maven生命周期,我将如何触发远程安装?mvn依赖:unpack?这不是非常具有描述性或直观性.是否可以在不编写插件的情况下创建自定义目标(例如project:install)?
使用Maven是公司的标准,所以请不要提供替代品 - 我几乎坚持我拥有的东西
Ric*_*ler 14
好的,我认为以下可能会做你需要的.这种方法的缺点是,在执行后续构建时,每个部署之间将存在间隔.这可以接受吗?
在每个项目中使用相同的名称定义配置文件(例如"发布").在该配置文件中,您可以定义配置以使用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>
Run Code Online (Sandbox Code Playgroud)
更新:根据您的评论:您可以使用依赖项插件来下载每个依赖项,除了父项不能依赖于子项,并且它将在子项之前构建.它必须是另一个项目.您还需要在某处获取将其部署到何处的信息.目前,您在各个项目中拥有目标信息,因此在部署项目中无法访问该信息.
采用这种方法,您可以在新项目中定义多个配置文件,每个工件一个.每个配置文件都定义了一个依赖项:复制执行以获取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>
Run Code Online (Sandbox Code Playgroud)
POM下面将帮助将jar的文件从项目构建目录复制到远程SFTP/FTP服务器.
由于出于安全原因我想从命令提示符传递密码,我使用了 -Dftp.password = password 执行上述命令后,maven项目目标文件夹中的所有jar文件都将部署在server.com上的MAVEN文件夹中
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>ftp</id>
<phase>install</phase>
<configuration>
<tasks>
<scp todir="user@server.com:/MAVEN/"
sftp="true" port="22" trust="true" password="${ftp.password}"
failonerror="false" verbose="true" passphrase="">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</scp>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)