how do I get sbt to gather all the jar files my code depends on into one place?

后端 未结 7 758
栀梦
栀梦 2020-12-24 12:47

I\'m new to sbt. I want it to put all the dependency jar files as well as my jar file into one place. SBT will run the app, but I\'ve got various dependencies s

相关标签:
7条回答
  • 2020-12-24 13:26

    Create a task in your build file like this:

    lazy val copyDependencies = TaskKey[Unit]("pack")
    
    def copyDepTask = copyDependencies <<= (update, crossTarget, scalaVersion) map {
      (updateReport, out, scalaVer) =>
        updateReport.allFiles foreach {
          srcPath =>
            val destPath = out / "lib" / srcPath.getName
            IO.copyFile(srcPath, destPath, preserveLastModified = true)
        }
    }
    

    Add the Task to a Project like this:

    lazy val HubSensors =
      Project("HubSensors", file("HubSensors"), settings = shared ++ Seq(
        copyDepTask,
        resolvers ++= Seq(novusRels),
        libraryDependencies ++= Seq(
          jodatime
        )
      )) dependsOn(HubCameraVision, JamServiceProxy, HubDAL)
    

    In the SBT console type:

    project [Project Name]
    pack
    
    0 讨论(0)
提交回复
热议问题