Getting a Play / SBT App Depends on Maven POM

The My Play 2 app is a subproject of the larger Maven app. The Play 2 application has dependencies in its parent - it gets access to data from it. Therefore, I want the build of the application to depend on an external Maven project.

Basically, I want to write this:

val main = play.Project(appName, appVersion, appDependencies).settings( // settings ).dependsOn(externalPom(baseDirectory(_ / "../pom.xml"))) 

But of course, this is not valid syntax.

I tried to define my play.Project as follows:

 val main = play.Project(appName, appVersion, appDependencies).settings( externalPom(baseDirectory(_ / "../pom.xml")) ) 

Which fails because (I think) the override causes Play not to load its own exception

I tried to define a new Project like this:

 lazy val data = Project("data", file(baseDirectory(_ / "..).settings( externalPom(baseDirectory(_ / "../pom.xml")) ) 

And depending on what doesn't work, because the main class is not detected.

Any suggestions on how to do this? I am new to SBT.

+6
source share
2 answers

I successfully use play2-maven-plugin

http://nanoko-project.imtqy.com/maven-play2-plugin/maven/release/

With this plugin, you also create a maven module for the play2 application, and you define the dependencies (your level of data access) in maven pom. The plugin ensures that playback receives the dependencies (it copies pom dependencies to unmanaged dependencies in the lib directory).

Using this plugin also avoids many tedious rearrangements, because you have everything in one project, so your IDE sees changes in all modules without recovery.

Also, when you use the plugin, you have no problem updating the dependencies of maven snapshots on the local maven repository (this sbt error is https://github.com/sbt/sbt/issues/321 ).

0
source

I just did it with play2-maven-plugin and sbt-pom-reader .

Here's how you need to set up 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") 
0
source

Source: https://habr.com/ru/post/943483/


All Articles