webdevelopersdiary / play2-maven-plugin

Automatically exported from code.google.com/p/play2-maven-plugin
0 stars 0 forks source link

M2Eclipse integration #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Make plugin IDE friendly.

I know, how to implement Eclipse integration only for now.

If anybody could help with other popular IDEs (Netbeans, Idea) integration, 
write here any informations, documentation links, etc.

Useful documentation:

https://docs.sonatype.org/display/M2ECLIPSE/Project+build+lifecycle+mapping
http://wiki.eclipse.org/M2E_compatible_maven_plugins
http://wiki.eclipse.org/M2E_Extension_Development

Original issue reported on code.google.com by gslowiko...@gmail.com on 1 Dec 2013 at 1:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
http://code.google.com/p/play2-maven-plugin/source/detail?r=338 - 
"META-INF/m2e/lifecycle-mapping-metadata.xml" file added.

Original comment by gslowiko...@gmail.com on 1 Dec 2013 at 1:22

GoogleCodeExporter commented 9 years ago
Hi, 

I'm trying to use your plugin (version 1.0.0-alpha5) in conjunction with m2e. 
Since this version doesn't have the lifecycle mapping metadata yet, I added 
this to my pom.xml :

<pluginManagement>
  <plugins>

    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <versionRange>[${play2.plugin.version},)</versionRange>
                <goals>
                  <goal>routes-compile</goal>
                  <goal>template-compile</goal>
                  <goal>closure-compile</goal>
                  <goal>coffee-compile</goal>
                  <goal>less-compile</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute>
                  <runOnIncremental>true</runOnIncremental>
                  <runOnConfiguration>true</runOnConfiguration>
                </execute>
              </action>
            </pluginExecution>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <versionRange>[${play2.plugin.version},)</versionRange>
                <goals>
                  <goal>compile</goal>
                  <goal>testCompile</goal>
                  <goal>enhance</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <ignore />
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>

  </plugins>
</pluginManagement>

It looks to work fine.

However, I have still 2 issues :

1) The Eclipse project has compilation errors. Eclipse cannot resolve the 
compiled Scala templates because the classes are generated into 
target/classes_managed. How can I add this folder in the Eclipse project 
classpath or configure the plugin to generate these templates into 
target/classes instead ?

2) When important the Maven project into Eclipse, m2e complains that it doesn't 
know the 'play2' packaging, the importation stops and the project is 
misconfigured. For the moment, the workaround was to remove the packaging (so 
it defaults to 'jar'), import the Maven project and then add back the 'play2' 
packaging... Is there any better solution to this ?

Thank you for the great work so far !

Original comment by simon.ba...@gmail.com on 25 Feb 2014 at 3:47

GoogleCodeExporter commented 9 years ago
Hi

This integration will be in the next version (1.0.0-alpha6) of the plugin.

I've already did some work (see 
http://play2-maven-plugin.googlecode.com/svn/trunk/plugin/play2-maven-plugin/src
/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml), but not finished 
yet. You have to use 1.0.0-alpha6-SNAPSHOT version.

Read Usage wiki, how to add snapshot repository.
See sample projects in trunk 
(http://play2-maven-plugin.googlecode.com/svn/trunk/test-projects/) because 
there are quite big changes related to issue #17.

There is one really big problem with M2E integration. M2E does not treat 
"play2" projects as Java projects at all. This is because there is no 
maven-compiler-plugin in "play2" lifecycle.
The workaround is to add

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <skipMain>true</skipMain> <!-- skip compile -->
                    <skip>true</skip> <!-- skip testCompile -->
                </configuration>
            </plugin>

to build/plugins section before import, and remove it after.

I will return to this issue soon, because M2E integration is not finished yet 
anyway.

Original comment by gslowiko...@gmail.com on 25 Feb 2014 at 4:26

GoogleCodeExporter commented 9 years ago
Hi, 

Thank you, I made it almost work.

But still, the compiled templates look to be inaccessible from Eclipse.

For example, in the test project "play22/java/helloworld/, the "Application" 
class shows 3 errors :

Description              Resource         Path                        Location 
Type
index cannot be resolved Application.java /helloworld/app/controllers line 38  
Java Problem
index cannot be resolved Application.java /helloworld/app/controllers line 28  
Java Problem
hello cannot be resolved Application.java /helloworld/app/controllers line 42  
Java Problem

However, if I list the target/classes folder, it looks to be there... :
user@host:helloworld$ ls -l target/classes/views/html/
total 56
-rw-r--r-- 1 user user 2026 Feb 26 08:33 hello$$anonfun$apply$1.class
-rw-r--r-- 1 user user 1281 Feb 26 08:33 hello$$anonfun$f$1.class
-rw-r--r-- 1 user user 2895 Feb 26 08:33 hello.class
-rw-r--r-- 1 user user 4477 Feb 26 08:33 hello$.class
-rw-r--r-- 1 user user 4410 Feb 26 08:33 index$$anonfun$apply$1.class
-rw-r--r-- 1 user user 1147 Feb 26 08:33 index$$anonfun$f$1.class
-rw-r--r-- 1 user user 2974 Feb 26 08:33 index.class
-rw-r--r-- 1 user user 3858 Feb 26 08:33 index$.class
-rw-r--r-- 1 user user 1398 Feb 26 08:33 
main$$anonfun$f$1$$anonfun$apply$1.class
-rw-r--r-- 1 user user 1241 Feb 26 08:33 main$$anonfun$f$1.class
-rw-r--r-- 1 user user 2836 Feb 26 08:33 main.class
-rw-r--r-- 1 user user 3842 Feb 26 08:33 main$.class

Strange...

Let me know if I can help you in any way !

Original comment by simon.ba...@gmail.com on 26 Feb 2014 at 7:43

GoogleCodeExporter commented 9 years ago
Hi Simon

I gave you wrong instructions (copied from wrong place). You have to add:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <skipMain>true</skipMain> <!-- skip compile -->
                    <skip>true</skip> <!-- skip testCompile -->
                </configuration>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <goals><goal>compile</goal></goals>
                    </execution>
                    <execution>
                        <id>default-testCompile</id>
                        <goals><goal>testCompile</goal></goals>
                    </execution>
                </executions>
            </plugin>

After importing add Scala nature (Scala IDE plugin required). It will replace 
Java Builder with Scala Builder.
Rebuild project if there are any errors.

I've just tested it and it works for me.

As you see, it's not easy now. The process must be improved.

Original comment by gslowiko...@gmail.com on 26 Feb 2014 at 11:56

GoogleCodeExporter commented 9 years ago
Hi,

Thanks, it works like a charm ! :)

Original comment by simon.ba...@gmail.com on 27 Feb 2014 at 1:30

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
http://code.google.com/p/play2-maven-plugin/source/detail?r=344 - BuildContext 
refreshing in routes and templates compilation mojos.

http://code.google.com/p/play2-maven-plugin/source/detail?r=346 - BuildContext 
refreshing - added in "coffee", "js" and "less" assets compilation mojos and 
improved in routes and templates compilation mojos.

Original comment by gslowiko...@gmail.com on 28 Feb 2014 at 12:12

GoogleCodeExporter commented 9 years ago
New 1.0.0-alpha6-SNAPSHOT deployed.

Original comment by gslowiko...@gmail.com on 28 Feb 2014 at 12:14

GoogleCodeExporter commented 9 years ago
Play2TemplateCompiler.compile method signature changed.

Original comment by gslowiko...@gmail.com on 3 Mar 2014 at 7:26

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/play2-maven-plugin/source/detail?r=394 - 
"plexus-utils" dependency version downgraded from 3.0.17 to 2.0.6 because of 
strange classloader bug in M2E 1.4

Details:

Description    Resource    Path    Location    Type
Execution default-routes-compile of goal
com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-alpha6-SNAPSHOT:rout
es-compile
failed: An API incompatibility was encountered while executing
com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-alpha6-SNAPSHOT:rout
es-compile:
java.lang.NoSuchMethodError:
org.codehaus.plexus.util.DirectoryScanner.setupMatchPatterns()V
-----------------------------------------------------
realm =   
plugin>com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-alpha6-SNAPSH
OT
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] =
file:/d:/home/gs/.m2/repository/com/google/code/play2-maven-plugin/play2-maven-p
lugin/1.0.0-alpha6-SNAPSHOT/play2-maven-plugin-1.0.0-alpha6-SNAPSHOT.jar
urls[1] =
file:/d:/home/gs/.m2/repository/com/google/code/play2-maven-plugin/play2-provide
r-api/1.0.0-alpha6-SNAPSHOT/play2-provider-api-1.0.0-alpha6-SNAPSHOT.jar
urls[2] =
file:/d:/home/gs/.m2/repository/org/apache/ant/ant/1.9.0/ant-1.9.0.jar
urls[3] =
file:/d:/home/gs/.m2/repository/org/apache/ant/ant-launcher/1.9.0/ant-launcher-1
.9.0.jar
urls[4] =
file:/d:/home/gs/.m2/repository/com/typesafe/config/1.2.0/config-1.2.0.jar
urls[5] =
file:/d:/home/gs/.m2/repository/backport-util-concurrent/backport-util-concurren
t/3.1/backport-util-concurrent-3.1.jar
urls[6] =
file:/d:/home/gs/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/pl
exus-interpolation-1.11.jar
urls[7] = file:/d:/home/gs/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
urls[8] =
file:/d:/home/gs/.m2/repository/org/apache/maven/shared/maven-common-artifact-fi
lters/1.4/maven-common-artifact-filters-1.4.jar
urls[9] =
file:/d:/home/gs/.m2/repository/org/codehaus/plexus/plexus-archiver/2.3/plexus-a
rchiver-2.3.jar
urls[10] =
file:/d:/home/gs/.m2/repository/org/codehaus/plexus/plexus-io/2.0.6/plexus-io-2.
0.6.jar
urls[11] =
file:/d:/home/gs/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.17/plexus-u
tils-3.0.17.jar
Number of foreign imports: 4
import: Entry[import org.sonatype.plexus.build.incremental from realm
ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm
ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm
ClassRealm[plexus.core, parent: null]]
import: Entry[import  from realm
ClassRealm[project>com.google.code.play2-maven-plugin.test-projects.play22.scala
:helloworld:1.0.0-alpha6-SNAPSHOT,
parent: ClassRealm[maven.api, parent: null]]]

-----------------------------------------------------
 (com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-alpha6-SNAPSHOT:routes-compile:default-routes-compile:generate-sources)   
pom.xml    /helloworld-1.0.0-alpha6-SNAPSHOT    line 90    Maven Build
Problem

I found the reason, but don't know what is the proper path to solve this.
The reason is "org.codehaus.plexus.util.DirectoryScanner" class is
loaded by

ClassRealm[plugin>com.google.code.play2-maven-plugin:play2-maven-plugin:1.0.0-al
pha6-SNAPSHOT,
parent: sun.misc.Launcher$AppClassLoader@aa4c7c]

and it's base class "org.codehaus.plexus.util.AbstractScanner" is loaded by

org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@107a705[org.eclipse.m2e
.maven.runtime:1.4.0.20130531-2315(id=195)]

M2Eclipse bundled version is 2.0.6.

When I call DirectoryScanner.scan(), it calls "setupMatchPatterns()"
method. This method was introduced in AbstractScanner class in
plexus-utils version 3.0.5
so it's not there in version 2.0.6.

Important notes:

M2E 1.5 depends on newer version of "plexus-utils" (3.0.15), so Play! plugin 
works (and worked before) with this version without problems.

Scala IDE 3.0.3 (current) version contains M2E 1.4, and I want Play! plugin to 
work with it.

Original comment by gslowiko...@gmail.com on 8 Apr 2014 at 10:46

GoogleCodeExporter commented 9 years ago
This bug is known as has already been fixed.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=422106 

Original comment by gslowiko...@gmail.com on 8 Apr 2014 at 7:48

GoogleCodeExporter commented 9 years ago
[EclipseIntegration] wiki page updated with better workaround proposal - 
maven-compiler-plugin in separate profile. Profile activated only inside 
Eclipse, never needed from CLI.

Original comment by gslowiko...@gmail.com on 29 Jan 2015 at 8:43

GoogleCodeExporter commented 9 years ago
https://code.google.com/p/play2-maven-plugin/source/detail?r=1181 - 'eclipse' 
profile added to all test projects.

Original comment by gslowiko...@gmail.com on 29 Jan 2015 at 9:29