cescoffier / maven-play2-plugin

A Maven Plugin to build Play2 applications
Apache License 2.0
49 stars 41 forks source link

Add target/scala-2.9.1/classes_managed to the project model classpath #3

Closed eskatos closed 12 years ago

eskatos commented 12 years ago

When opening/importing a maven project using the plugin, sources are marked with errors when importing compiled templates as this is the play2 build that generates them in target/scala-2.9.1/classes_managed.

I've tried using the build-helper-maven-plugin but it can only add sources to the project model. It's better than nothing because target/scala-2.9.1/src_managed contains everything needed so your project source are not marked with errors when importing compiled templates but theses generated sources are marked with errors because play2 generates .classes directly in target/scala-1.9.1/classes_managed. As a consequence generated sources are marked with errors because they rely on theses directly generated .class files.

I hope I made my point clear enough for you to understand :-)

Tu sum it up with have two options here :

I don't know maven enough to know if the second point is only doable.

/Paul

cescoffier commented 12 years ago

Hi,

Got the issue :-)

Unfortunately, Maven does not support having several 'classes' directory. I already faced the issue in the android-maven-plugin.

One possibility would be to configure the compile goal to copy the classes to target/classes. May be a good idea anyway, as Maven users are expecting having their classes there anyway. If we go on this path, we should do the same for test classes.

WDYT ?

cescoffier commented 12 years ago

It seems that play2 is copying _classesmanaged to classes. So we just have to copy those to target/classes.

eskatos commented 12 years ago

Does all maven enabled IDEs pick up classes in target/classes for project classpath, that I'm not sure.

I tried to do this on a project :

cp -a target/scala-2.9.1/classes_managed/* target/classes

And Netbeans still miss the generated view classes : http://snag.gy/OA9qH.jpg

Since "a picture is worth a thousand words", here is what I came up with as a partial solution :

Play2 generates :

So, adding the target/scala-2.9.1/src_managed/main folder to the project model using the build-helper-maven-plugin allows me to get the generated views and routes in the IDE classpath.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>play2-add-managed-sources</id>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${project.build.directory}/scala-2.9.1/src_managed/main</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

It works very well but there's only a little glitch : http://snag.gy/oJnSm.jpg

Here you can see that Netbeans show some red alert on the added source directory, nothing severe but I was looking for a way to solve this properly.

Anyway, populating target/classes with the actual compiled classes of the play2 project is a different issue but seems to be a good idea !

eskatos commented 12 years ago

That said, I don't know at all how Netbeans automagically take care of the added source directory. IOW, if it gets it dynamically from the maven model or if it parses the pom.xml for build-helper-maven-plugin configuration ...

I can live with the build-helper-maven-plugin setup. This issue is all about comfort and should not slow down the 1.0 release :-)

cescoffier commented 12 years ago

IDEs are generally handling the build-helper-maven-plugin. At least IDEA and Eclipse are supporting this plugin 'natively'.

So the solution is more tricky than expected, because even copying the classes won't make it work as IDEs are not checking already compiled classes. So for now the 'build-helper-maven-plugin' is probably the best option. I'm going to add a FAQ section in the doc mentioning it.

I propose to postpone this issue to the version 1.1.0.

cescoffier commented 12 years ago

FAQ published. I've reused one of your picture.

eskatos commented 12 years ago

Perfect, I think that this issue can now be closed.