在 sbt 和 Scala play 框架之间共享源代码/库

发布于 2024-12-01 01:14:15 字数 417 浏览 2 评论 0原文

我正在 Scala 中开发两个相关的应用程序。一种是使用 SBT 构建的服务器端处理引擎,并无头运行(在 cron 作业上)进行一些数字运算。另一个是用 Scala 编写并在 play 框架上运行的网站。

我希望能够在两者之间共享代码,但由于它们每个人(SBT 和 Play)对目录结构以及如何构建东西都有自己的想法,所以我很不清楚应该如何做到这一点。我讨厌复制和粘贴 .scala 文件 - 但我也不热衷于使用符号链接并让它们都从相同的文件构建。

如果可能的话,我会接受让 Play 脚本运行 SBT 以根据需要构建库。如果这是唯一的方法,那么我也可以使用 SBT 为 Play 构建 jar,然后将它们复制到位。但我经常同时开发两者(它们是一个更大的应用程序的一部分),如果它们一起更新,一切都会更加顺利。这是否可能,或者我是否缺少另一种更简单的技术?

谢谢,亚历克斯

I have two related apps I am developing in Scala. One is a server-side processing engine built using SBT and running headlessly doing some number crunching (on a cron job). The other is a web site written in Scala and running on the play framework.

I have code that I would like to be able to share between the two, but as each of them (SBT and Play) has their own ideas about directory structure and how to build things it's pretty unclear to me how I should do this. I'd hate to copy and paste the .scala files - but I'm also not keen on using sym links and having them both build from the same files.

If it were possible, I would accept getting the Play scripts to run SBT to build libraries as required. If it were the only way then I would also be OK with using SBT to build jars for Play and then copying them into place. But I'm often developing both simultaneously (they are parts of a bigger app) and it would all work much more smoothly if they updated together. Is this even possible, or if there's another simpler technique I'm missing?

Thanks, Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霊感 2024-12-08 01:14:15

唯一简单的方法是使用 SBT 构建 JAR 并让 Play 使用它们。

关于如何复制,您有 2 个选择:

  • 您手动构建它们并将其复制到 Play 中的 libs 文件夹(您可以编写脚本以使其不那么烦人)
  • 您为 JAR 使用自定义存储库(ala Nexus 存储库)并使用 Play dependency.yml 指向该存储库并更新。有了这个,您还需要经常运行 playsync --deps 并调整版本,所以我不确定它在开发过程中是否有意义(一旦 JAR 发布,它就更有意义)虽然完整)

The only easy way is to build JARs with SBT and make Play use them.

On how to copy, you have 2 options:

  • You manually build and copy them over to the libs folder in Play (you can script that to make it less annoying)
  • You use a custom repository for your JARs (ala Nexus repository) and use Play dependencies.yml to point to that repo and update. With this you would also need to run play sync --deps often and to tweak the versions, so I'm not sure if it makes too much sense during dev (it makes more sense once the JARs are complete though)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文