Because I’m still sometimes doing some PHP-Coding, I wanted to get started with Maven for PHP, however, I ran into various problems with the way it was described on their webpage.
Unfortunately, also the mailing list did not respond to my mails, so I had to dig into the source alone.
The problem I had was, that although I added the profile-php-maven to my settings.xml, the archetypes where not recognized, resulting in an error-message like this, when trying to create a new project:
1 2 3 | mvn archetype:generate -DarchetypeGroupId=org.phpmaven - DarchetypeArtifactId=php5-lib-archetype -DarchetypeVersion=1.0 - DgroupId=org.sample -DartifactId=my-app |
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:generate] [WARNING] No archetype repository found. Falling back to central repository (http://repo1.maven.org/maven2). [WARNING] Use -DarchetypeRepository=if archetype's repository is elsewhere. Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.0/php... org.apache.maven.archetype.downloader.DownloadNotFoundException: Requested download does not exist. at org.apache.maven.archetype.downloader.DefaultDownloader.download (DefaultDownloader.java:62) at org.apache.maven.archetype.common.DefaultArchetypeArtifactManager.exists (DefaultArchetypeArtifactManager.java:310) at org.apache.maven.archetype.ui.DefaultArchetypeGenerationConfigurator.configureArchetype (DefaultArchetypeGenerationConfigurator.java:103) at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execute (CreateProjectFromArchetypeMojo.java:168) at org.apache.maven.plugin.DefaultPluginManager.executeMojo (DefaultPluginManager.java:453) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals (DefaultLifecycleExecutor.java:559) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal (DefaultLifecycleExecutor.java:513) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal (DefaultLifecycleExecutor.java:483) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures (DefaultLifecycleExecutor.java:331) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments (DefaultLifecycleExecutor.java:228) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute (DefaultLifecycleExecutor.java:142) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129) at org.apache.maven.cli.MavenCli.main(MavenCli.java:301) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java: 315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java: 430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) Caused by: org.apache.maven.artifact.resolver.ArtifactNotFoundException: Unable to locate resource in repository Try downloading the file manually from the project website. Then, install it using the command: mvn install:install-file -DgroupId=org.phpmaven -DartifactId=php5- lib-archetype -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file Alternatively, if you host your own repository you can deploy the file there: mvn deploy:deploy-file -DgroupId=org.phpmaven -DartifactId=php5- lib-archetype -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file -Durl= [url] -DrepositoryId=[id] org.phpmaven:php5-lib-archetype:jar:1.0 from the specified remote repositories: php5-lib-archetype-repo (http://repo1.maven.org/maven2) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve (DefaultArtifactResolver.java:212) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveAlways (DefaultArtifactResolver.java:80) at org.apache.maven.archetype.downloader.DefaultDownloader.download (DefaultDownloader.java:54) ... 21 more Caused by: org.apache.maven.wagon.ResourceDoesNotExistException: Unable to locate resource in repository at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData (LightweightHttpWagon.java:100) at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:68) at org.apache.maven.artifact.manager.DefaultWagonManager.getRemoteFile (DefaultWagonManager.java:475) at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifact (DefaultWagonManager.java:355) at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve (DefaultArtifactResolver.java:196) ... 23 more Caused by: java.io.FileNotFoundException: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.0/php... at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1311) at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputData (LightweightHttpWagon.java:83) ... 27 more [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] The desired archetype does not exist (org.phpmaven:php5-lib- archetype:1.0) [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 5 seconds [INFO] Finished at: Mon Dec 07 02:15:42 CET 2009 [INFO] Final Memory: 16M/288M [INFO] ------------------------------------------------------------------------
So.. maven does not recognize my profile, even not after upgrading to maven 2.2…. So I did checkout the source, and compiled the stuff myself:
1 2 3 | svn checkout http://svn.key-tec.de/php-maven/trunk/ cd trunk/org.phpmaven.multimaster/ |
however, trying to build the project was not successfull because of miss-spelled directories and outdated dependencies
1 | mvn clean compile install |
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [ERROR] FATAL ERROR [INFO] ------------------------------------------------------------------------ [INFO] Error building POM (may not be this project's POM). Project ID: unknown Reason: Could not find the model file '/home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin'. for project unknown [INFO] ------------------------------------------------------------------------ [INFO] Trace org.apache.maven.reactor.MavenExecutionException: Could not find the model file '/home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin'. for project unknown at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) at org.codehaus.classworlds.Launcher.main(Launcher.java:375) Caused by: org.apache.maven.project.ProjectBuildingException: Could not find the model file '/home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin'. for project unknown at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1575) at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:506) at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200) at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:604) at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:487) at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:560) at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:391) ... 12 more Caused by: java.io.FileNotFoundException: /home/domdorn/work/php-maven/bla/bla2/trunk/org.phpmaven.multimaster/org.phpmaven.plugin (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:106) at hidden.org.codehaus.plexus.util.xml.XmlReader. (XmlReader.java:124) at hidden.org.codehaus.plexus.util.xml.XmlStreamReader. (XmlStreamReader.java:67) at hidden.org.codehaus.plexus.util.ReaderFactory.newXmlReader(ReaderFactory.java:118) at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1570) ... 18 more [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Wed Dec 09 19:22:46 CET 2009 [INFO] Final Memory: 3M/73M [INFO] ------------------------------------------------------------------------
I fixed those with two small + simple commands:
1 2 3 | svn mv maven-php-plugin org.phpmaven.plugin # rename directory # replace outdated wagon-ftp dependency for i in `find . -iname 'pom.xml' | grep -v svn`; do sed 's/1.0-20080208/1.0-beta-6/g' $i > ${i}_xx ; mv ${i}_xx $i; done |
after this, a simple
1 | mvn install |
did the trick for me.
I'm now creating new php-maven projects like this:
1 | mvn archetype:generate -DarchetypeGroupId=org.phpmaven -DarchetypeArtifactId=php5-lib-archetype -DarchetypeVersion=1.1-SNAPSHOT -DgroupId=com.dominikdorn -DartifactId=my-example-app |
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'. [INFO] Setting property: velocimacro.messages.on => 'false'. [INFO] Setting property: resource.loader => 'classpath'. [INFO] Setting property: resource.manager.logwhenfound => 'false'. [INFO] [archetype:generate {execution: default-cli}] [WARNING] No archetype repository found. Falling back to central repository (http://repo1.maven.org/maven2). [WARNING] Use -DarchetypeRepository=if archetype's repository is elsewhere. [INFO] snapshot org.phpmaven:php5-lib-archetype:1.1-SNAPSHOT: checking for updates from php5-lib-archetype-repo Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar [INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2) Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar [INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2) Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar [INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2) Define value for version: : 1.0-SNAPSHOT Define value for package: : com.dominikdorn.php-maven-example-app Confirm properties configuration: groupId: com.dominikdorn artifactId: my-example-app version: 1.0-SNAPSHOT package: com.dominikdorn.php-maven-example-app Y: : Y Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar [INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2) Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar [INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2) Downloading: http://repo1.maven.org/maven2/org/phpmaven/php5-lib-archetype/1.1-SNAPSHOT/php5-lib-archetype-1.1-SNAPSHOT.jar [INFO] Unable to find resource 'org.phpmaven:php5-lib-archetype:jar:1.1-SNAPSHOT' in repository php5-lib-archetype-repo (http://repo1.maven.org/maven2) [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/src/test/php/apptest.php [line 6,column 9] : $app is not a valid reference. [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/src/test/php/apptest.php [line 7,column 9] : $this- is not a valid reference. [WARNING] org.apache.velocity.runtime.exception.ReferenceException: reference : template = archetype-resources/src/test/php/apptest.php [line 7,column 42] : $app- is not a valid reference. [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 29 seconds [INFO] Finished at: Wed Dec 09 19:54:29 CET 2009 [INFO] Final Memory: 15M/166M [INFO] ------------------------------------------------------------------------
It still does not find the dependencies, but at least it creates my project.
after fixing a issue with the auto-generated php-unit test, I can package my lib with this
1 | mvn clean compile package |
[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Sample PHP 5 library project [INFO] task-segment: [clean, compile, package] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory /tmp/test/test3/my-example-app/target [INFO] [plugin:descriptor {execution: default-descriptor}] [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /tmp/test/test3/my-example-app/src/main/resources [INFO] [php:php-validate {execution: default-php-validate}] [INFO] [plugin:descriptor {execution: default-descriptor}] [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /tmp/test/test3/my-example-app/src/main/resources [INFO] [php:php-validate {execution: default-php-validate}] [INFO] [resources:testResources {execution: default-testResources}] [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /tmp/test/test3/my-example-app/src/test/resources [INFO] [php:phpunit {execution: default-phpunit}] [INFO] Surefire report directory: /tmp/test/test3/my-example-app/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- apptest.php Running AppTest Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.001249 Results : Tests run: 1, Failures: 0, Errors: 0 [INFO] [jar:jar {execution: default-jar}] [INFO] Building jar: /tmp/test/test3/my-example-app/target/my-example-app-1.0.jar [INFO] [plugin:addPluginArtifactMetadata {execution: default-addPluginArtifactMetadata}] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4 seconds [INFO] Finished at: Wed Dec 09 20:04:51 CET 2009 [INFO] Final Memory: 27M/294M [INFO] ------------------------------------------------------------------------
I'm in contact with Christian Widemann from Key-Tec to resolve the outstanding problems.
3 Responses to Getting started with Maven for PHP
Patrick
April 14th, 2010 at 17:52
Hi Dominik,
are there any news from Christian Widemann or in general to this?
Cheers
Patrick
Dominik Dorn
April 15th, 2010 at 22:26
Actually, no. I don’t have any news on this. I must admit, I haven’t done anything with maven for php since then, as I’m now using quercus and simply put the php stuff into src/main/webapp
ifima.ru » Blog Archive » Использование Maven для PHP
July 16th, 2011 at 21:09
[…] Getting started with Maven for PHP […]