PHPプロジェクトをMavenで管理する
元ネタ。
http://www.php-maven.org/
下にまとめる。
setting.xmlを下記のように設定。
<settings> <profiles> <profile> <id>profile-php-maven</id> <pluginRepositories> <pluginRepository> <id>release-repo1.php-maven.org</id> <name>PHP-Maven 2 Release Repository</name> <url>http://repos.php-maven.org/releases</url> <releases> <enabled>true</enabled> </releases> </pluginRepository> <pluginRepository> <id>snapshot-repo1.php-maven.org</id> <name>PHP-Maven 2 Snapshot Repository</name> <url>http://repos.php-maven.org/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> <repositories> <repository> <id>release-repo1.php-maven.org</id> <name>PHP-Maven 2 Release Repository</name> <url>http://repos.php-maven.org/releases</url> <releases> <enabled>true</enabled> </releases> </repository> <repository> <id>snapshot-repo1.php-maven.org</id> <name>PHP-Maven 2 Snapshot Repository</name> <url>http://repos.php-maven.org/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>profile-php-maven</activeProfile> </activeProfiles> </settings>
これでPHP-Mavenプラグインのあるリポジトリサーバを覗ける。
下記のようなコマンドを実行するとPHPライブラリ作成用プロジェクトを生成できる。
mvn archetype:generate -DarchetypeGroupId=org.phpmaven -DarchetypeArtifactId=php5-lib-archetype -DarchetypeVersion=2.0-SNAPSHOT -DgroupId=[グループID] -DartifactId=[アーティファクトID] -Dversion=[バージョン]
すると下記の内容が書かれたPOMを持つMavenプロジェクトができる。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.phpmaven</groupId> <artifactId>php-parent-pom</artifactId> <version>2.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>[グループID]</groupId> <artifactId>[アーティファクトID]</artifactId> <packaging>php</packaging> <version>[バージョン]</version> <build> <plugins> <plugin> <groupId>org.phpmaven</groupId> <artifactId>maven-php-plugin</artifactId> <extensions>true</extensions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>3.0</version> <configuration> <reportPlugins> <plugin> <groupId>org.phpmaven</groupId> <artifactId>maven-php-plugin</artifactId> <reportSets> <reportSet> <reports> <report>phpdocumentor</report> </reports> </reportSet> </reportSets> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-report-plugin</artifactId> <version>2.10</version> <reportSets> <reportSet> <reports> <report>report-only</report> </reports> </reportSet> </reportSets> </plugin> </reportPlugins> </configuration> </plugin> </plugins> </build> <dependencies> <!-- phpUnit for PHP 5 --> <dependency> <groupId>de.phpunit</groupId> <artifactId>PHPUnit</artifactId> <version>3.6.10</version> <type>phar</type> </dependency> </dependencies> </project>
Mavenプロジェクトのディレクトリ構造は下記のような形。
[プロジェクトルート] |-- pom.xml `-- src |-- main | `-- php | `-- *** | `-- *** | `-- app.php |`-- test | `-- php | `-- *** | `-- *** | `-- apptest.php `-- site |-- site.xml `-- apt `-- index.apt
下記のようなコマンドを実行するとPHPWeb作成用プロジェクトを生成できる。
mvn archetype:generate -DarchetypeGroupId=org.phpmaven -DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0-SNAPSHOT -DgroupId=[グループID] -DartifactId=[アーティファクトID] -Dversion=[バージョン]