php-maven / maven-php-plugin

A maven plugin for dependency management and quality assurance for PHP projects.
http://www.php-maven.org/
Apache License 2.0
37 stars 29 forks source link

Archetype still not working #10

Closed achingbrain closed 12 years ago

achingbrain commented 12 years ago

Since you've fixed issue #9 but not yet updated the snapshots on http://repos.php-maven.org/snapshots , I cloned the git repo, went into /branches/2.0-SNAPSHOT/archetypes/php5-web-archetype and did a mvn install.

Now running:

$ mvn archetype:generate \ -DarchetypeGroupId=org.phpmaven \ -DarchetypeArtifactId=php5-web-archetype \ -DarchetypeVersion=2.0-SNAPSHOT \ -DgroupId=org.sample \ -DartifactId=my-app \ -Dversion=0.0.1-SNAPSHOT

works, hurrah! However after changing to the newly created my-app directory, running:

$ mvn package

does not. Instead, I get this error message:

$ mvn package [INFO] Scanning for projects... [ERROR] The build could not read 1 project -> [Help 1] [ERROR]
[ERROR] The project org.sample:my-app:0.0.1-SNAPSHOT (/Users/alex/Sites/foo/my-app/pom.xml) has 1 error [ERROR] Non-resolvable parent POM: Could not find artifact org.phpmaven:php-parent-pom:pom:2.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

Looking at the pom there is indeed a reference to a parent project. Commenting out the reference to the parent and running mvn package again, I get:

$ mvn package [INFO] Scanning for projects... [ERROR] The build could not read 1 project -> [Help 1] [ERROR]
[ERROR] The project org.sample:my-app:0.0.1-SNAPSHOT (/Users/alex/Sites/foo/my-app/pom.xml) has 1 error [ERROR] Unknown packaging: php @ line 20, column 16 [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

There's likely to be another issue as the pom generated by the archetype has no repositories or pluginRepositories so maven will not know where to get the maven-php-plugin from.

mepeisen commented 12 years ago

Can you reproduce the first error with "mvn -X package" and please send me the whole output?

achingbrain commented 12 years ago

Looks like it was caused by the right repositories not being defined. Of course, you have instructions up here http://www.php-maven.org/prepare.html to add the repos to ~/.m2/settings.xml, but I'd ideally like to avoid that as it will mean that the php-maven.org repositories get queried for every maven build I do, PHP or not. Plus there's an extra step to get the archetype to work, increasing friction.

Anyway, adding the following to the pom makes it build:

<pluginRepositories>
    <pluginRepository>
        <id>release-repos.php-maven.org</id>
        <name>PHP-Maven Release Repository</name>
        <url>http://repos.php-maven.org/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
    <pluginRepository>
        <id>snapshot-repos.php-maven.org</id>
        <name>PHP-Maven 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-repos.php-maven.org</id>
        <name>PHP-Maven Release Repository</name>
        <url>http://repos.php-maven.org/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
    <repository>
        <id>snapshot-repos.php-maven.org</id>
        <name>PHP-Maven Snapshot Repository</name>
        <url>http://repos.php-maven.org/snapshots</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Would it be possible to do away with the requirement for a PHP maven project to be a child project of php-parent-pom? It strikes me that it won't play nicely in a multiple module project. For example if I have a web project, I may have one module that builds and tests PHP, another that builds using flex-mojos, etc, in which case I'd need to be able to define the parent project, so:

my-project
    |
    -----> my-project-php (builds using maven-php-plugin)
    |
    -----> my-project-flash (builds using flex-mojos)
mepeisen commented 12 years ago

Currently there is no way. See https://jira.codehaus.org/browse/MNG-5244 However the most important thing is adding maven-php-plugin to the build plugins and setting the source/test-source folders. You can of course copy this from the parent plugin and add it directly to your pom.

To not always query php-maven you can use the offline flag (-o) at command line. Another way is to use a mirror. If you are a member of a big company it is recommended to setup a mirror nexus server in your intranet. That mirror will cache each artifact and reduce the number of queries to the central repository or to php-maven. The reason maven queries the repository every time is caused by the snapshopts. We still have not a stable 2..0 release. As soon as we have it everyone should migrate to it. A released artifact maven was able to resolve and download won't be queried again.

achingbrain commented 12 years ago

Looks like you've been banging your head against this for a little while. For what it's worth, the flex-mojos project appear to have solved this particular problem (or at least worked round it) as they've managed to introduce their own packaging (swc & swf) and compile a non-Java language (ActionScript in this case) from a location other than /src/main/java while not mandating a particular parent project. I've fixed up their modular-webapp archetype and put an example up at https://github.com/achingbrain/flex-multi-module-sample so you can see what I mean (run "mvn package -DskipTests" after cloning the repo as otherwise you'll need a standalone Flash player to run the unit tests).

...

The problem with using -o is that no repositories at all will be queried, which is not what I'm after. What I mean is that when I'm working on a non-PHP project, I still want it to resolve snapshots, but I don't need it to try to resolve its snapshots from the php-maven repo. The simplest way to do this would be to declare the repositories other than central needed by a project in it's pom - that way the project is self contained and there's minimal further setup to do.

I'm not working on this for a big company, it's just a spare time project so setting up a mirror would be overkill.

I'm very much looking forward to a stable 2.0 release - hopefully you'll be able to get it into central and this part of the conversation will become moot.

mepeisen commented 12 years ago

@repository/settings topic: Nope. You can of course put the repository configuration inside a profile and remove the section. The command line option "-P" can be used to activate the php-maven profile on demand. And even in the pom itself you can activate the profile. It is no need to put the whole repository configuration inside the pom. However thats the maven way. :-)

I do not want to reinvent the wheel or battle against the maven profiles or any other thing. Because this is one of the benefits we get from maven.

Commiting the plugin to central is one option. However maven 3.0.4 already comlpains because "maven-____-plugin" naming is not wanted for plugins outside group "org.apache.maven.plugins". So there will be some change in the future. But not yet. I am concentrating on other things.

@src topic: The php-parent-pom is not required but recommended. Of course you can merge them to your own pom. I am always planning to support a clean and easy way to configure this things. Hopefully the maven guys introduce a common way to build and integrate non-java super poms. But if they don't find a way we rely on setting the sources manually. Look at your poms. Your poms are setting the source folder to a different location too :)

php-parent-pom will contain the following things: 1) setting source folders and test source folders 2) setting correct dependencies on build plugins (for eample the jetty webserver) 3) setting up distribution management for our repositories. no other things will every be located within the parent pom. So if you are using your own repository and if you are seeting up your own build plugin configuration (especially web server integration) there is no need to use the php-parent-pom at all.

mepeisen commented 12 years ago

closing now :)