All Projects → ThoughtWorksInc → sbt-ammonite-classpath

ThoughtWorksInc / sbt-ammonite-classpath

Licence: MIT License
Export the classpath for Ammonite and Almond

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to sbt-ammonite-classpath

sbt-findbugs
FindBugs static analysis plugin for sbt.
Stars: ✭ 47 (+62.07%)
Mutual labels:  sbt, sbt-plugin
sbt-kubeyml
Sbt plugin to help deploy Scala applications to Kubernetes
Stars: ✭ 37 (+27.59%)
Mutual labels:  sbt, sbt-plugin
gatling-sbt-plugin
Gatling Plugin for SBT
Stars: ✭ 105 (+262.07%)
Mutual labels:  sbt, sbt-plugin
sbt-sass
A fork of the sbt-sass repository which seems to be abandoned.
Stars: ✭ 32 (+10.34%)
Mutual labels:  sbt, sbt-plugin
sbt-flaky
Detect flaky tests with sbt
Stars: ✭ 35 (+20.69%)
Mutual labels:  sbt, sbt-plugin
sbt-graphql
SBT plugin to generate and validate graphql schemas written with Sangria
Stars: ✭ 94 (+224.14%)
Mutual labels:  sbt, sbt-plugin
sbt-rewarn
Make sbt always display compilation warnings, even for unchanged files.
Stars: ✭ 42 (+44.83%)
Mutual labels:  sbt, sbt-plugin
Sbt Dynver
An sbt plugin to dynamically set your version from git
Stars: ✭ 243 (+737.93%)
Mutual labels:  sbt, sbt-plugin
sbt-example
Run Scaladoc as unit tests
Stars: ✭ 30 (+3.45%)
Mutual labels:  sbt, sbt-plugin
sbt-elm
Scala Build Tool (SBT) plugin for the Elm programming language
Stars: ✭ 44 (+51.72%)
Mutual labels:  sbt, sbt-plugin
sbt-sonar
An sbt plugin which provides an easy way to integrate Scala projects with SonarQube.
Stars: ✭ 62 (+113.79%)
Mutual labels:  sbt, sbt-plugin
sbt-bazel
Easily convert SBT projects to Bazel workspaces
Stars: ✭ 55 (+89.66%)
Mutual labels:  sbt, sbt-plugin
sbt-babel
An SBT plugin to perform Babel compilation.
Stars: ✭ 12 (-58.62%)
Mutual labels:  sbt, sbt-plugin
chuckwagon
a Scala/sbt AWS Lambda Toolkit
Stars: ✭ 29 (+0%)
Mutual labels:  sbt, sbt-plugin
sbt-ghpages
git, site and ghpages support for sbt projects.
Stars: ✭ 94 (+224.14%)
Mutual labels:  sbt, sbt-plugin
sbt-swagger-2
sbt plugin for generating Swagger JSON schemas during build
Stars: ✭ 13 (-55.17%)
Mutual labels:  sbt, sbt-plugin
Sbt Tpolecat
scalac options for the enlightened
Stars: ✭ 227 (+682.76%)
Mutual labels:  sbt, sbt-plugin
Sbt Fresh
sbt-plugin to create an opinionated fresh sbt project
Stars: ✭ 229 (+689.66%)
Mutual labels:  sbt, sbt-plugin
sbt-travisci
An sbt plugin to integrate with Travis CI
Stars: ✭ 44 (+51.72%)
Mutual labels:  sbt, sbt-plugin
sbt-project-switcher
A sbt plugin to switch project in a snappy way⚡️
Stars: ✭ 36 (+24.14%)
Mutual labels:  sbt, sbt-plugin

sbt-ammonite-classpath

sbt-ammonite-classpath is an sbt plug-in to export classpath of an sbt project to Ammonite Script, which can be then used in Ammonite or Almond. Also supports running Ammonite REPL directly with desired classpath.

Usage

// project/plugins.sbt
addSbtPlugin("com.thoughtworks.deeplearning" % "sbt-ammonite-classpath" % "latest.release")
// src/main/scala/mypackage/MyObject.scala
package mypackage

object MyObject {
  def hello() = println("Hello, World!")
}

Exporting Classpath for Almond or Ammonite

$ sbt Compile/fullClasspath/exportToAmmoniteScript && amm --predef target/scala-2.12/fullClasspath-Compile.sc
...
...
...
[success] Total time: 1 s, completed Apr 17, 2018 10:11:08 AM
Loading...
Compiling /private/tmp/example/target/scala-2.12/fullClasspath-Compile.sc
Welcome to the Ammonite Repl 1.1.0
(Scala 2.12.4 Java 1.8.0_162)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ mypackage.MyObject.hello() 
Hello, World!

Alternatively the classpath can be dynamically loaded by an import $file statement, too:

$ amm
Loading...
Welcome to the Ammonite Repl 1.1.0
(Scala 2.12.4 Java 1.8.0_162)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import $file.target.`scala-2.12`.`fullClasspath-Compile` 
Compiling /private/tmp/example/target/scala-2.12/fullClasspath-Compile.sc
import $file.$                                          

@ mypackage.MyObject.hello() 
Hello, World!

Launching Ammonite REPL

This plugin also supports directly running Ammonite REPL from sbt. Similar to using above scopes you may launch the Ammonite REPL with desired classpath and compile scope as follows:

sbt "{scope}:{classpath}::launchAmmoniteRepl"

Where scope can be one of compile, test and runtime, while classpath can be one of fullClasspath, dependencyClasspath, managedClasspath, unmanagedClasspath.

Example:

sbt "test:dependencyClasspath::launchAmmoniteRepl"

If you would like to run Ammonite REPL with full classpath, you can simply use launchAmmoniteRepl task within compile (or any other) scope without having to specify classpath task scope:

sbt "compile:launchAmmoniteRepl" 
# or simply (without scope, compile will be implied)
sbt launchAmmoniteRepl

initialCommands setting is also supported. If your initialCommands or launchAmmoniteRepl / initialCommands setting is not appropriate for a given scope, you can override it in one of this plugin's scopes. For example if you would like to only have import ammonite.ops._ in your Ammonite REPL but not Scala REPL, you can do as follows:

...

console / initialCommands := "println(\"Hello Console\")",

Compile / launchAmmoniteRepl / initialCommands += "\nimport ammonite.ops._"

// or simply launchAmmoniteRepl / initialCommands
...

When you run sbt launchAmmoniteRepl, both commands will be in effect:

sbt launchAmmoniteRepl
...
[info] running ammonite.Main --predef /private/tmp/example/target/scala-2.13/fullClasspath-Compile.sc --predef-code "println("Hello Console")
[info] import ammonite.ops._"
Loading...
Hello Console
Welcome to the Ammonite Repl 2.2.0-4-4bd225e (Scala 2.13.3 Java 1.8.0_252)
@ ls! pwd 
res2: LsSeq = 
".bloop"          ".gitignore"      ".vscode"         "build.sbt"       'target
".git"            ".metals"         'LICENCE          'project          'test
".github"         ".scalafmt.conf"  "README.md"       'src

@

By default it will use the "latest.release" version of Ammonite, but if you would like to change it, you can override ammoniteVersion setting, e.g.:

ammoniteVersion := "2.1.4"
Test / ammoniteVersion := "2.2.0"

Related work

sbt-ammonite is an sbt 0.13 plug-in to launch Ammonite. It automatically passes the classpath instead of creating a sc file. However, it does not support Almond.

Requirements

  • Sbt 1.x
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].