加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 自定义“运行”类似项目的任务

发布时间:2020-12-16 18:33:25 所属栏目:安全 来源:网络整理
导读:默认情况下,我的SBT构建的运行任务执行我在src / main / scala /中自动找到的主类. 如何为项目添加新任务,其行为与运行任务类似,但在src / util / scala中找到主类?该任务应该在类路径上使用src / main / scala运行util main方法. 我正在使用SBT 0.12.4和完
默认情况下,我的SBT构建的运行任务执行我在src / main / scala /中自动找到的主类.

如何为项目添加新任务,其行为与运行任务类似,但在src / util / scala中找到主类?该任务应该在类路径上使用src / main / scala运行util main方法.

我正在使用SBT 0.12.4和完整的多项目配置.

解决方法

下面定义了一个新配置,它从src / util / scala编译源代码,并定义util:run和util:run-main以从新配置运行主类.编译和运行时,src / main / scala中的编译源可在类路径中使用.

import sbt._
import Keys._

object MyBuild extends Build
{
   // Define a new configuration named `util`.
   //   Extending `Compile` means the main classpath is available to `util`
   lazy val Util = config("util").extend(Compile)

   // Add the new configuration to the project.
   // Add the new settings.
   lazy val root = Project("root",file(".")).configs(Util).settings( utilSettings : _*)

   // Add the basic source,compilation,and packaging settings
   //   as well as custom run methods.
   lazy val utilSettings = inConfig(Util)( Defaults.configSettings ++ utilRunSettings )

   // Settings that define `run` and `run-main` to use the
   // classpath from the enclosing configuration.
   // (The standard `run` methods use the `Runtime` configuration.
   lazy val utilRunSettings = Seq(
        run <<= Defaults.runTask(fullClasspath,mainClass in run,runner in run),runMain <<= Defaults.runMainTask(fullClasspath,runner in run)
   )
}

(在0.13上测试过,但应该在0.12上测试.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读