Collecting dependencies under sbt 0.10 (putting all dependency jars to target/scala-version/lib/)

前端 未结 3 1197
慢半拍i
慢半拍i 2021-02-09 00:19

I\'m using sbt 0.10 with Scala 2.9.1.

I\'ve read http://groups.google.com/group/simple-build-tool/browse_thread/thread/792e5360877e78/987b6af687b8e33b?lnk=gst&q=coll

相关标签:
3条回答
  • 2021-02-09 00:57

    See task xitrum-package: https://github.com/ngocdaothanh/xitrum/blob/master/plugin/src/main/scala/XitrumPlugin.scala

    It copies all dependencies to directory target/xitrum_package.

    0 讨论(0)
  • 2021-02-09 01:06

    The various "Classpath" keys contain different views onto the classpath, but probably the easiest thing is to modify the sbt-assembly plugin to simply drop the jars into a directory instead of doing the unzip/rezip cycle. The plugin is very small (only 150 lines) and it's pretty obvious from a cursory glance what the right place to change is.

    0 讨论(0)
  • 2021-02-09 01:19

    You didn't specify the ivy configuration to copy the configurations from but here's a fully working example that will copy all your managed dependencies to the target/<scala version>/lib folder (scala version is given by the crossTarget task). Just copy this and put it in the file project/Build.scala (or whatever filename you want) :

    import sbt._
    import Keys._
    
    object MyBuild extends Build {
    
      lazy val copyDependencies = TaskKey[Unit]("copy-dependencies")
    
      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)
        }
      }
    
      lazy val root = Project(
        "root",
        file("."),
        settings = Defaults.defaultSettings ++ Seq(
          copyDepTask
        )
      )
    }
    
    

    If you want a specific configuration, replace

    updateReport.allFiles by updateReport.select(configuration = Set("compile")) or whatever ivy configuration you want.

    0 讨论(0)
提交回复
热议问题