开发者

Is there a good way to mavenify a play! framework application?

I am using play as web app framework and I love it, but I would like to know if there is a good way to declare the pom for a play! app ?

As the sources files are meant to be in specials (not maven standard) folders, and that the goal is not to generate a target file, but to permit to manage the projet in diferents IDE (Eclipse, Net开发者_如何学运维beans, ...)

It would be great if it would be possible to link pom.xml dependencies with the 1.2.X conf/dependencies.yml specific format.

Thanks.


An updated answer to this question as play install does not work with Play 2

I just had to mavenify a Play 2 application.

To do this, I used play2-maven-plugin and sbt-pom-reader.

I used sbt-pom-reader to keep the hot reloading feature which is not supported by play2-maven-plugin yet.

This is how you need to configure your play2-maven project:

<my-maven-project>/
  pom.xml                  <- Your maven build
  build.sbt                <- the sbt Play 2 configuration
  project/
     build.properties      <- the sbt version specification
     build.scala           <- the sbt build definition
     plugins.sbt           <- the sbt plugin configuration

  ..                       <- Whatever files are normally in your maven project.

Each of the files should have the following contents.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.foo</groupId>
    <artifactId>bar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>play2</packaging>
    <name>My mavenified Play 2 application</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <play2.version>2.2.1</play2.version>
        <play2-scala.version>2.10</play2-scala.version>
        <play2.plugin.version>1.0.0-alpha5</play2.plugin.version>
        <scala.version>2.10.2</scala.version>
    </properties>
    <repositories>
        <repository>
            <id>typesafe</id>
            <name>Typesafe - releases</name>
            <url>http://repo.typesafe.com/typesafe/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play_${play2-scala.version}</artifactId>
            <version>${play2.version}</version>
        </dependency>
        <!-- only if using Java -->
        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-java_${play2-scala.version}</artifactId>
            <version>${play2.version}</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>${basedir}/app</sourceDirectory>
        <resources>
            <resource>
                <directory>${basedir}/conf</directory>
            </resource>
            <resource>
                <directory>${basedir}</directory>
                <includes>
                    <include>public/**</include>
                </includes>
            </resource>
        </resources>
        <!--<outputDirectory>target/scala-${play2-scala.version}/classes</outputDirectory>-->
        <plugins>
            <plugin>
                <groupId>com.google.code.play2-maven-plugin</groupId>
                <artifactId>play2-maven-plugin</artifactId>
                <version>${play2.plugin.version}</version>
                <extensions>true</extensions>
                <dependencies>
                    <dependency>
                        <groupId>com.google.code.play2-maven-plugin</groupId>
                        <artifactId>play2-provider-play22</artifactId>
                        <version>${play2.plugin.version}</version>
                    </dependency>
                </dependencies>
                <!-- only if using Java -->
                <configuration>
                    <mainLang>java</mainLang>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

build.sbt:

play.Project.playJavaSettings //or play.Project.playScalaSettings

project/build.properties:

sbt.version=0.13.0

project/build.scala:

object BuildFromMavenPomSettings extends com.typesafe.sbt.pom.PomBuild

project/plugins.sbt:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-pom-reader" % "1.0.1")

Now you can use Maven for builds and SBT for development with hot reload.


There are some different plugins that support this:

  1. AbsurdHero's Play Pure Maven Plugin. This supports converting scala.html files to scala, linking static assets into the target directory, and monitoring the source files and reloading to the test server automatically. It does not have any support for creating a jar / war / zip that you can deploy. It does not require Play to be installed on the machine, so it will work with a CI server, although you need to get the plugin jar on to the CI machine, for example using a local Maven repository like Nexus.
  2. The Nanoko play-2 maven plugin. I haven't used this one yet - it says it is a wrapper around the play framework so it requires Play to installed on the build machine. It does support building war's and debugging or running the application.

Any others? I would be interested to hear other options?


Yes, there are play maven module. So you need to install it "play install maven" then call "play mvn:init". then each time you update it call "play mvn:up". Integration is not very good, means it one way maven to play dependency. and not all maven commands supported. But playfremwork2 will be based completly on SBT(aka maven on Scala)


Since Play 2.4 you can disable the PlayLayoutPlugin to use normal, Maven-style layout instead of Play's traditional layout. You just need to add disablePlugins(PlayLayoutPlugin) into your sbt project definition.

See: https://www.playframework.com/documentation/2.6.x/Anatomy#Default-SBT-layout

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜