2

这就是我面临的情况:目前我有两个 Maven 项目,一个只描述依赖项、存储库等(父级)和一个继承另一个 pom.xml 的子级。未来会创建更多的模块,遵循与孩子相同的模型。

我们决定将项目的站点(使用 maven-site-plugin 生成)部署到此时只能通过sftp访问的位置。而且我发现无法定义站点位置,<distributionManagement>因为我无法集成 sftp 协议(我尝试使用 wagon-ssh-external)。

结果,我创建了一个脚本,该脚本连接到远程机器并在站点部署阶段上传我们站点部署到的本地文件夹的内容:

echo "Uploading the site.."
lftp -u ${username},${password} sftp://${host} <<EOF
mirror -R --delete-first $sitedir $remotedir
echo "Exiting from lftp.."
bye
EOF
echo "Terminating script execution.."

这对父站点非常有效,在本地创建站点后立即上传站点,但是当子站点到达脚本末尾时,它无法正确完成,打印Terminating script execution..并停留在那里。

我正在使用 Eclipse,这是带有默认 Maven 插件(v. 3.0.2)的最新版本(3.7)。为了在 Eclipse 中生成和部署站点,我右键单击父项目 >​​ Run as > Maven build... > parent clean site-deploy

这些是父母的部分pom.xml

<distributionManagement>
 <!-- Generate the site locally, then it'll be uploaded to the server -->
 <!-- Children will append their artifact ID to the base url  -->
 <site>
  <id>project-name</id>
  <name>Project Name</name>
  <url>file://${env.HOME}/testsite/</url>
 </site>
</distributionManagement>
...
<build> 
<pluginManagement>
 <plugins>
  <plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <version>1.2.1</version>
  </plugin>
 </plugins>
</pluginManagement>
<plugins>
 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-site-plugin</artifactId>
  <version>3.0</version>
  <configuration>
    ...
 </plugin>
 <plugin>
  <groupId>org.codehaus.mojo</groupId>          
  <artifactId>exec-maven-plugin</artifactId>
  <inherited>false</inherited>
  <executions>
   <execution>
    <id>sh</id>
    <phase>site-deploy</phase>
    <goals>
     <goal>exec</goal>
    </goals>
    <configuration>
     <executable>sh</executable>
     <arguments>
      <argument>publish-site.sh</argument>
      <argument>${localsitedir}</argument>
      ...
     </arguments>
    </configuration>
   </execution>
  </executions>
 </plugin>
</plugins>
</build>

从孩子那里:

<build>
 <plugin>
  <groupId>org.codehaus.mojo</groupId>          
  <artifactId>exec-maven-plugin</artifactId>
  <executions>
   <execution>
    <id>sh</id>
    <phase>site-deploy</phase>          
    <goals>
     <goal>exec</goal>
    </goals>
    <configuration>
     <executable>sh</executable>
     <arguments>
      <argument>../parent/publish-site.sh</argument>
      <argument>${localsitedir}/child</argument>
      ...
     </arguments>
    </configuration>
   </execution>
  </executions>
 </plugin>
</build>

我尝试了不同的方法来配置exec插件(不使用pluginManagement,继承插件的父级配置,只重写参数部分等),它在完成脚本时总是被阻塞并且不会结束执行。

该站点已正确上传,但是当然,我不想在每次要更新站点时手动终止 Maven 构建执行(另外,计划将项目中的工件部署到 Jenkins 服务器,因此该站点部署希望届时能够工作)。

4

1 回答 1

0

我的回答是基于很多猜测......我遇到了一个关于不终止的 SSH 命令的类似问题,原因是:

也许'lftp'启动一个不退出的进程,也许(可能)maven-exec插件在stdout和stderr上循环以在退出之前打印所有相关消息。如果不是所有作家都关闭,它就会卡住。

尝试将 'lftp' 的输出重定向到 /dev/null,以防万一。

于 2014-05-26T17:41:46.933 回答