这就是我所面临的情况:目前我有两个Maven项目,一个除了描述依赖项,存储库等(父项)一个继承对方的pom.xml的孩子。将来会有更多的模块被创建,遵循与孩子相同的模型。使用exec插件从Maven 3执行脚本 - 被阻止
我们决定通过sftp将项目的网站(使用maven-site-plugin生成)部署到此时可访问的位置。我发现无法在<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,最后一个版本(3.7)与默认的Maven插件(v。3.0.2)。为了在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服务器,所以网站的部署希望在那时起作用)。
这可能听起来很愚蠢,但你有没有尝试在publish-site.sh结尾添加exit 0语句? – drgn