1

I have:

  • main project
  • sub project called "shopping"

I would like to use views from main project inside the subproject. My code of sub project controller:

package controllers.shopping;

public class Application extends Controller {

  public static Result index() {
      return ok(views.html.confirmation.render("ok"));
  }
}

And my main build file

lazy val shopping = project.in(file("modules/shopping"))

val main = project.in(file("."))
    .dependsOn(shopping).aggregate(shopping)

My model class in submodule common:

@Entity
public class AppMode {
    public static AppMode getCurrentConfigurationEntry() {
        return JPA.em().find(AppMode.class, 1L);
    }
}
masterdany88
  • 5,041
  • 11
  • 58
  • 132

1 Answers1

1

Since main depends on shopping adding a dependency the other way around as well would create a circular dependency so sbt wouldn't be able to know which project to build first.

Break the logic you want out into a second subproject that you depend on from both shopping and main and you will be able to access them in both shopping and main.

johanandren
  • 11,249
  • 1
  • 25
  • 30
  • So You propose to create subproject "main" for all shared (between all submodules) logic. So what should I put in first project (not in module dir)? – masterdany88 Sep 10 '14 at 11:26
  • I would rather call it "common" or something like that rather than "main". I would probably also try to keep the root project a superproject with no sources in and then submodules with the actual code. (I would claim this is best practice working with multimodule sbt projects) – johanandren Sep 10 '14 at 11:40
  • Thanks for Your help. I will follow Your instruction :D – masterdany88 Sep 10 '14 at 12:16
  • How Can I add a library to subproject. F.e. jpa library. To which one build should I put depedency and how to import in to source code? – masterdany88 Sep 10 '14 at 13:05
  • You would need it for the subproject for compiling and maybe testing and you would need it for the end project for runtime. Checkout the sbt tutorial/docs to get a better understanding: http://www.scala-sbt.org/0.13/tutorial/Multi-Project.html – johanandren Sep 10 '14 at 13:30
  • How can I access to models in submodule? I am getting an error:[IllegalArgumentException: Unknown entity: models.AppMode] Which is in submodule common. I've tried already: models.common.AppMode and common.models.AppMode but it dosnt work. – masterdany88 Sep 15 '14 at 06:47
  • During runtime the classes do not know what module/jar they come from, so if you put it in common/app/models then the package is common. Did you put a dependency from the module you are using it from to common? – johanandren Sep 15 '14 at 08:00
  • I've changed package to package models.common; And this resolve the problem. But another came out. Can You see at my next question: http://stackoverflow.com/questions/25842651/play2-calling-controllers-models-views-in-submodule – masterdany88 Sep 15 '14 at 10:19
  • According to your instruction I've run into another problem. How configure jpa/hibernate in play framework to scan submodules models entity. I've created new posts for that: http://stackoverflow.com/questions/25846796/adding-jpa-hibernate-entity-in-submodule-in-playframework-to-entity-manager-to and the second one http://stackoverflow.com/questions/25863415/how-to-persist-models-entity-in-playframework-submodule-using-jpa-hibernate/25863762?noredirect=1#25863762 CAN YOU HELP ME WITH THAT??? – masterdany88 Sep 16 '14 at 09:09