Building Play framework app with Maven

127 views
Skip to first unread message

Harshit Patel

unread,
Aug 25, 2015, 1:56:26 PM8/25/15
to play-framework
We have a Play framework app, which is part of a larger java project, built using maven. So far, we have been using the play2-maven-plugin (https://code.google.com/p/play2-maven-plugin/), to build the app as part of the same build. The plugin works great and has enabled us to build without having the need for our build server to have sbt. 

We are now trying to upgrade to Java 8, when I noticed an issue with the plugin. While the latest version of the plugin (1.0.0-beta3) has support for Play 2.4, which uses JDK8, when I built the app using JDK8, I found that the files were being compiled to  major version: 50 (1.6 which corresponds to JDK 1.6), despite being built with JDK8. I checked this by using "javap" on the built jar file.

Looking at the source code (https://code.google.com/p/play2-maven-plugin/source/checkout) of the plugin, it looks like the plugin has hardcoded the maven-compiler-plugin to use compiler version 1.6

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

Also, while all the other source files are being compiled to  major version: 50, the routes file in the application is being compiled to major version: 52 (which corresponds to JDK8).

Is there anyway to configure the play2-maven-plugin to compile everything to the same compiler version ? Or is there another way to build Play framework applications using maven only, and not having to depend on sbt ?

Thanks,
Harshit


Harshit Patel

unread,
Aug 26, 2015, 6:30:25 PM8/26/15
to play-framework
Changing subject to include play version 

Grzegorz Słowikowski

unread,
Aug 31, 2015, 4:56:20 AM8/31/15
to play-fr...@googlegroups.com
Hi

Sorry for delay.

The compiler plugin configuration you cited is used for building the
plugin itself. It has nothing to do with projects using it.
If you use "play2" packaging defined by this plugin
sbt-compiler-maven-plugin
(https://code.google.com/p/sbt-compiler-maven-plugin/) is used, not
maven-compiler-plugin.

There are two configuration parameters, "javacOptions" and
"scalacOptions", for Javac and Scalac configuration.
See "Setting additional compiler options" section in
https://code.google.com/p/sbt-compiler-maven-plugin/wiki/Usage

Add any of Javac options
(http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#options)
to "javacOptions". Separate them with spaces, for example:
<javacOptions>-g -source 1.8 -target 1.8</javacOptions>
For Scala compiler you probably need:
<scalacOptions>-deprecation -unchecked -target:jvm-1.8</scalacOptions>
(I did not test it).

Regards
Grzegorz Slowikowski


On 2015-08-27 00:30, Harshit Patel wrote:
> Changing subject to include play version
>
> On Tuesday, August 25, 2015 at 10:56:26 AM UTC-7, Harshit Patel wrote:
>
> We have a Play framework app, which is part of a larger java
> project, built using maven. So far, we have been using the
> play2-maven-plugin (https://code.google.com/p/play2-maven-plugin/
> <https://code.google.com/p/play2-maven-plugin/>), to build the app
> as part of the same build. The plugin works great and has enabled us
> to build without having the need for our build server to have sbt.
>
> We are now trying to upgrade to Java 8, when I noticed an issue with
> the plugin. While the latest version of the plugin (1.0.0-beta3) has
> support for Play 2.4, which uses JDK8, when I built the app using
> JDK8, I found that the files were being compiled to major version:
> 50 (1.6 which corresponds to JDK 1.6), despite being built with
> JDK8. I checked this by using "javap"on the built jar file.
>
> Looking at the source code
> (https://code.google.com/p/play2-maven-plugin/source/checkout
> <https://code.google.com/p/play2-maven-plugin/source/checkout>) of
> the plugin, it looks like the plugin has hardcoded the
> maven-compiler-plugin to use compiler version 1.6
>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
> <version>3.3</version>
> <configuration>
> <source>1.6</source>
> <target>1.6</target>
> </configuration>
> </plugin>
>
> Also, while all the other source files are being compiled to major
> version: 50, the routesfile in the application is being compiled to
> major version: 52(which corresponds to JDK8).
>
> Is there anyway to configure the play2-maven-plugin to compile
> everything to the same compiler version ? Or is there another way to
> build Play framework applications using maven only, and not having
> to depend on sbt ?
>
> Thanks,
> Harshit
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "play-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to play-framewor...@googlegroups.com
> <mailto:play-framewor...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/play-framework/09e62b92-6b32-47b4-809c-a7efd4d11fb9%40googlegroups.com
> <https://groups.google.com/d/msgid/play-framework/09e62b92-6b32-47b4-809c-a7efd4d11fb9%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Harshit Patel

unread,
Aug 31, 2015, 3:38:18 PM8/31/15
to play-framework
Thanks for getting back.
Using the scalacOptions and javacOptions seems to have resolved the issue for me.
I am still getting a " 'jvm-1.8' is not a valid choice for '-target'" error if I use <scalacOptions>-deprecation -unchecked -target:jvm-1.8</scalacOptions>, but that looks related to the scala version (2.10.4) that I am using. Upgrading the scala version that should resolve that issue.

Thanks again!
Reply all
Reply to author
Forward
0 new messages