Phing似乎无法使用标记/命令运行Composer。它似乎在当前目录中查找composer.phar。由于它没有将composer.phar作为命令执行,而是将字符串composer.phar传递给php二进制文件,因此它无法使用系统路径来查找composer.phr(除非我错了?)
如何让Phing正确运行composer而不明确告诉它composer.phar在哪里?我不想这么做,因为这个构建脚本应该在任何安装了Composer和Phing的系统上运行。
我的项目有一个build.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-awesome-app" default="build" basedir=".">
<target name="build">
<composer command="install"></composer>
</target>
</project>
我在OSX上通过MAMP Pro运行PHP,所以所有与PHP相关的脚本/二进制文件都在以下目录中:
/Applications/MAMP/bin/php/php7.0.0/bin
# ls -al /Applications/MAMP/bin/php/php7.0.0/bin
total 120544
drwxrwxr-x 18 eric admin 612 25 Jul 10:14 .
drwxrwxr-x 8 eric admin 272 12 Jul 09:46 ..
-rwxr-xr-x 1 eric admin 1705349 14 Jul 19:40 composer
lrwxr-xr-x 1 eric admin 8 25 Jul 10:14 composer.phar -> composer
-rwxrwxr-x 1 eric admin 942 9 Dec 2015 pear
-rwxrwxr-x 1 eric admin 963 9 Dec 2015 peardev
-rwxrwxr-x 1 eric admin 879 9 Dec 2015 pecl
lrwxr-xr-x 1 eric admin 9 15 Dec 2015 phar -> phar.phar
-rwxrwxr-x 1 eric admin 14854 9 Dec 2015 phar.phar
-rwxr-xr-x 1 eric admin 797 25 Jul 09:12 phing
-rwxrwxr-x 1 eric admin 18944064 9 Dec 2015 php
-rwxrwxr-x 1 eric admin 18850440 9 Dec 2015 php-cgi
-rwxrwxr-x 1 eric admin 4126 9 Dec 2015 php-config
-rwxrwxr-x 1 eric admin 19149192 9 Dec 2015 phpdbg
-rwxrwxr-x 1 eric admin 4627 9 Dec 2015 phpize
lrwxr-xr-x 1 eric admin 12 13 Jul 23:29 phpunit -> phpunit.phar
-rwxr-xr-x@ 1 eric staff 2988429 13 Jul 23:28 phpunit.phar
运行phing的结果是:
# phing
Buildfile: /Users/eric/Development/php/phpstorm/my-awesome-app/build.xml
my-awesome-app > build:
[composer] executing /Applications/MAMP/bin/php/php7.0.0/bin/php composer.phar install
BUILD FAILED
/Users/eric/Development/php/phpstorm/my-awesome-app/build.xml:4:8: Composer binary not found, path is "composer.phar"
Total time: 0.0980 seconds
我已经使用exec声明作为解决方案:
<exec command="composer install" />
这将使用系统路径来查找composer脚本/phar(我已将composer链接到composer.phar并使其可执行。
我不会将这个答案标记为选定的答案,因为我相信内置的composer命令应该能够工作,而不必在构建文件中指定composer.phar的完整路径。
如果向composer标记添加一个空的php属性,那么只要composer在您的路径中,它就应该正确运行。
<composer php="" composer="composer" command="install" />