英文:
Publish one of several modules as a library using SBT
问题
I have a program that divides nicely into two modules, the business logic (BL) and the command line interface (CLI).
我有一个程序,很好地分为两个模块,业务逻辑(BL)和命令行界面(CLI)。
I'd like to publish BL as a library so it can also be used in a web app, both on the server (JVM) and the browser (ScalaJS).
我想将BL发布为一个库,这样它既可以在服务器(JVM)上,也可以在浏览器(ScalaJS)上的Web应用程序中使用。
Is it possible to publish just the BL module using SBT? If so, how?
是否可以只使用SBT发布BL模块?如果可以,怎么做?
I know how to put BL into its own project and publish the entire project as a library. I could then suck that into the original program with the CLI as well as the web app. But it seems easier to maintain if the BL and CLI could simply live as two modules in the same project and publish the one that I need elsewhere.
我知道如何将BL放入自己的项目并将整个项目发布为库。然后,我可以将其引入具有CLI的原始程序以及Web应用程序。但如果BL和CLI只需作为同一项目中的两个模块存在并发布我需要的一个模块,似乎更容易维护。
Thanks for any pointers.
感谢任何指导。
英文:
I have a program that divides nicely into two modules, the business logic (BL) and the command line interface (CLI).
I'd like to publish BL as a library so it can also be used in a web app, both on the server (JVM) and the browser (ScalaJS).
Is it possible to publish just the BL module using SBT? If so, how?
I know how to put BL into its own project and publish the entire project as a library. I could then suck that into the original program with the CLI as well as the web app. But it seems easier to maintain if the BL and CLI could simply live as two modules in the same project and publish the one that I need elsewhere.
Thanks for any pointers.
答案1
得分: 1
如果您已经知道如何发布项目,也知道如何设置多项目,那么下一步就是设置相应的模块发布设置并从该模块运行任务。
您的 build.sbt
应该像这样:
ThisBuild / organization := "org"
ThisBuild / version := "version"
ThisBuild / scalaVersion := "scalaVersion"
lazy val bl = (project in file("bl"))
.settings(
// settings for bl
)
lazy val cli = (project in file("cli"))
.settings(
// settings for cli
)
然后,您可以从子项目运行任务,使用 subproject/task
。根据上述 build.sbt
文件,运行任务的命令应该是:
> sbt bl/publish
英文:
If you already know how to publish the project and you also know how to setup multi projects, the next step is to setup the corresponding settings for publishing the module and run the task from that one.
your build.sbt
should be like
ThisBuild / organization := "org"
ThisBuild / version := "version"
ThisBuild / scalaVersion := "scalaVersion"
lazy val bl = (project in file("bl"))
.settings(
// settings for bl
)
lazy val cli = (project in file("cli"))
.settings(
// settings for cli
)
and then you can run a task from a subproject doing subproject/task
. Based on the previous build.sbt
file, the command to run the task should be like
> sbt bl/publish
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论