使用 exec 插件从 Maven 3 执行脚本 - 被阻止

发布于 2024-12-10 22:28:49 字数 3507 浏览 0 评论 0原文

这就是我面临的情况:目前我有两个 Maven 项目,一个除了描述依赖项、存储库等(父项目)之外什么也不做,另一个子项目继承另一个项目的 pom.xml。将来将会创建更多模块,遵循与子模块相同的模型。

我们决定将项目站点(使用 maven-site-plugin 生成)部署到目前只能通过 sftp 访问的位置。我发现无法在 中定义站点位置,因为我无法集成 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.."

这非常适合父站点,在本地创建站点后立即上传站点,但是当子进程到达脚本末尾时,它无法正确完成,打印 Terminate scriptexecution.. 并停留在那里。

我使用的是 Eclipse,最新版本 (3.7),带有默认的 Maven 插件 (v. 3.0.2)。为了在 Eclipse 中生成并部署站点,我右键单击了父项目 >运行为> Maven 构建...>> 父级清理站点部署

这些是父级 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 服务器,因此站点希望届时部署能够正常工作)。

This is the situation I'm facing: at the moment I have two Maven projects, one that does nothing but describing dependencies, repositories, etc. (the parent) and a child which inherits the other's pom.xml. There'll be more modules to be created in the future, following the same model as the child.

We decided to deploy the projects' sites (generated with maven-site-plugin) to a location accessible at this moment only via sftp. And I found it impossible to define the site location in <distributionManagement> because I couldn't integrate the sftp protocol (I tried using wagon-ssh-external).

As a result, I've created a script that connects to the remote machine and uploads the contents of a local folder where our site is deployed during the site-deploy phase:

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.."

This works perfectly for the parent site, uploading the site right after it's created locally, but when the child gets at the end of the script, it doesn't finish properly, prints Terminating script execution.. and stays there.

I'm using Eclipse, the last version (3.7) with the default Maven plugin (v. 3.0.2). To generate and deploy the site in Eclipse, I've right-clicked the parent project > Run as > Maven build... > parent clean site-deploy.

These are parts of the parent's 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>

And from the child:

<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>

I've tried different ways to configure the exec plugin (without using pluginManagement, inheriting the parent's configuration of the plugin and only rewriting the arguments part, etc..) and it always gets blocked when finishing the script and doesn't end the execution.

The site is uploaded correctly, but of course, I don't want to manually terminate the Maven build execution each time I want to update the site (also, it is planned to deploy artifacts from the project to a Jenkins server, so the site deployment hopefully would be working by then).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2024-12-17 22:28:49

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

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

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

My answer is based on a lot of speculation... I faced a similar issue about a SSH command that do not terminate and the reason was:

Maybe ' lftp ' starts a process that do not exit, and maybe (probably), the maven-exec plugin loops on stdout and stderr to print all relevant messages before to exit. If there are not closed by all writers, it stucks.

Try to redirect output of 'lftp' to /dev/null, just in case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文