Play框架[2.4.x]使用子模块 [英] Play Framework [2.4.x] Working with Sub Modules

查看:94
本文介绍了Play框架[2.4.x]使用子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用以下文档: https://www.playframework.com /documentation/2.4.x/SBTSubProjects ,并已在主模块和子模块中拆分了一个大型项目.

I've been working with these docs: https://www.playframework.com/documentation/2.4.x/SBTSubProjects and have split up a large project in a main and a sub module.

一些7000编译器错误,大量的咖啡因以及哇-希望我以前知道"的后来,我让该项目再次使用其新的模块化布局进行工作.

Some 7000 compiler errors, lots of caffeine and a whole to of "wow -- wish I knew that before"'s later I have the project working once more with it's new modular layout.

现在,我想创建第二个子模块.

Now I want to create a second sub-module.

我们将主模块称为ROOT,我们可以将子模块A ModA和子模块B ModB划分为子模块.

Let's call the main module ROOT and we'll can sub-module A ModA and sub-module B ModB.

ROOT将取决于ModA和ModB

ROOT will depend upon ModA and ModB

ModA不会依赖任何内容

ModA will not depending on anything

ModB将取决于ModA

ModB will depend upon ModA

让ModA和ModB成为同级兄弟会更优雅(阅读:可维护),或者拥有一系列指示继承流程的子模块在模式上是否优雅?

Will it be more elegant (read: maintainable) to have ModA and ModB be siblings or is it mode elegant to have a chain of submodules indicating the flow of inheritance?

ROOT-> ModB-> ModA

ROOT -> ModB -> ModA

如果(当)我们添加ModC和ModD等,这会变得一团糟,所以我希望我们可以使用同级模型进行此操作.

This will get mess(ier) if (when) we add ModC and ModD etc so I'm hoping we can do this with the sibling's model.

我相信大多数魔法都出现在这里:

Most of the magic appears here I believe:

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val ROOT = (project in file("."))
    .enablePlugins(PlayScala).dependsOn(ModA).aggregate(ModA)

我假设可以链接dependsOnaggregate调用.

I'll presume that I can chain the dependsOn and aggregate calls.

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val moduleB = (project in file("modules/ModB")).enablePlugins(PlayScala)

    lazy val ROOT = (project in file("."))
.enablePlugins(PlayScala).dependsOn(ModA)
.aggregate(ModA).dependsOn(ModB).aggregate(ModB)

使用同级模型如何声明ModB对ModA的依赖性? (假设使用ModB的build.sbt)

Using the siblings model how would the dependancy of ModB to ModA be declared? (assuming in build.sbt of ModB)

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val ROOT = (project in file("."))
    .enablePlugins(PlayScala).dependsOn(ModA).aggregate(ModA)

推荐答案

这应该很好:

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val moduleB = (project in file("modules/ModB")).enablePlugins(PlayScala).dependsOn(moduleB)

    lazy val ROOT = (project in file("."))
.enablePlugins(PlayScala).dependsOn(moduleB)

它将暂时依赖于modA.还请注意,dependsOn和Aggregation应该引用惰性val的名称,而不是文件夹名称.

It will transitively depend on mod A. Also notice that dependsOn and aggregate should reference the lazy val's name, not the folder name.

在这种情况下,由于您具有依赖关系,因此我认为您实际上不需要汇总.这是一个同时具有聚合和多个依赖关系的更复杂的示例:

I don't think you actually need the aggregate in this case since you have dependencies. here is a more complex example with both aggregate and multiple dependencies:

lazy val moduleA = (project in file("modules/ModA")).enablePlugins(PlayScala)

lazy val moduleC = (project in file("modules/ModC")).enablePlugins(PlayScala)

lazy val moduleB = (project in file("modules/ModB")).enablePlugins(PlayScala).dependsOn(moduleB)

lazy val myapp = (project in file("myapp")).enablePlugins(PlayScala).dependsOn(moduleB, moduleC)

lazy val batch = (project in file("batch")).enablePlugins(PlayScala).dependsOn(moduleB)

lazy val ROOT = (project in file("."))
.aggregate(myapp, batch)

这样,顶层(根)实际上没有代码并且不依赖任何人,它只是聚合了您的webapp和它的同批程序,它们都依赖于ModB,而ModB本身又依赖于ModA

This way the toplevel (root) doesn't actually have code and doesn't depend on anyone, it simply aggregates you webapp and it's companion batch which both depend on ModB which itself depends on ModA

这篇关于Play框架[2.4.x]使用子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆