Skip to content

Instantly share code, notes, and snippets.

@orrsella
Last active December 12, 2015 00:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save orrsella/4682495 to your computer and use it in GitHub Desktop.
Save orrsella/4682495 to your computer and use it in GitHub Desktop.
Instructions on how to reproduce sbt global plugin reload bug.

Instructions on how to reproduce sbt global plugin reload bug. Related links:

https://groups.google.com/forum/?hl=en&fromgroups=#!topic/simple-build-tool/x33MRCzNpww sbt/sbt#272

Directory and File Structure

~/SbtHome/                      # used as sbt.global.base
    plugins/
        plugins.sbt             # should be empty at beginning

~/SbtProj                       # the empty project we'll test on
    project/
        Build.scala             # build definition; should be .scala file, don't use build.sbt
    sbt-launcher-script.sh      # launcher script

sbt-lanucher-script.sh

#!/bin/sh
SBT_OPTS='-Dsbt.global.base=/Users/orr/SbtHome/ '$SBT_OPTS
exec java -Xmx512M ${SBT_OPTS} -XX:MaxPermSize=512M -jar /usr/local/Cellar/sbt/0.12.2/libexec/sbt-launch.jar "$@"

Notice that the -Dsbt.global.base param value has my absolute path, don't forget to change it accordingly.

Build.scala

Just a simple empty project:

import sbt._
import sbt.Keys._

object MyBuild extends Build {
  lazy val mySettings = Defaults.defaultSettings ++ Seq(
    name := "my-test-proj",
    organization := "com.example",
    version := "0.1.0-SNAPSHOT")

  lazy val proj = Project("my-test-proj", file("."), settings = mySettings)
}

Reproduction Sequence

  1. Make sure you have the above file/folder structure and that plugins.sbt is empty.

  2. Enter SbtProj/ folder, start sbt with the custom launch script once, and then exit sbt:

cd SbtProj/
chmod +x sbt-launcher-script.sh
./sbt-launcher-script.sh

Output from running launcher script:

Getting net.java.dev.jna jna 3.2.3 ...
:: retrieving :: org.scala-sbt#boot-jna
    confs: [default]
	1 artifacts copied, 0 already retrieved (838kB/10ms)
Getting org.scala-sbt sbt 0.12.2 ...
:: retrieving :: org.scala-sbt#boot-app
	confs: [default]
	40 artifacts copied, 0 already retrieved (8381kB/46ms)
Getting Scala 2.9.2 (for sbt)...
:: retrieving :: org.scala-sbt#boot-scala
	confs: [default]
	4 artifacts copied, 0 already retrieved (20090kB/44ms)
[info] Loading global plugins from /Users/orr/SbtHome/plugins
[info] Updating {file:/Users/orr/SbtHome/plugins/}default-9f82cf...
[info] Resolving org.scala-sbt#precompiled-2_10_0;0.12.2 ...
[info] Done updating.
[info] Loading project definition from /Users/orr/SbtProj/project
[info] Updating {file:/Users/orr/SbtProj/project/}default-2448b4...
[info] Resolving org.scala-sbt#precompiled-2_10_0;0.12.2 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/orr/SbtProj/project/target/scala-2.9.2/sbt-0.12/classes...
[info] Set current project to my-test-proj (in build file:/Users/orr/SbtProj/)
>

And exit sbt:

> exit
  1. Now, after the project has been opened once in sbt, edit global plugins file, found at SbtHome/plugins/plugins.sbt to include some plugin:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")

It doesn't matter which plugin we use. In this example we use sbt-igea, which we expect will add the command gen-idea.

  1. Relaunch sbt using the same script as before:
./sbt-launcher-script.sh

Output from launching sbt again:

[info] Loading global plugins from /Users/orr/SbtHome/plugins
[info] Updating {file:/Users/orr/SbtHome/plugins/}default-9f82cf...
[info] Resolving org.scala-sbt#precompiled-2_10_0;0.12.2 ...
[info] Done updating.
[info] Loading project definition from /Users/orr/SbtProj/project
[info] Set current project to my-test-proj (in build file:/Users/orr/SbtProj/)
> 

Notice that sbt doesn't complain about a plugin not found, or anything like that.

  1. Try to use the newly should-be-available gen-idea command:
> gen-idea
[error] Not a valid command: gen-idea
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: gen-idea
[error] gen-idea
[error]         ^
> 

As we can see, even tho we added the plugin, the command isn't available.

  1. Enter the "plugins" project (the project/ project), clean it, and return:
> reload plugins
[info] Loading global plugins from /Users/orr/SbtHome/plugins/project
[info] Updating {file:/Users/orr/SbtHome/plugins/project/}default-aea1cb...
[info] Resolving org.scala-sbt#precompiled-2_10_0;0.12.2 ...
[info] Done updating.
[info] Loading global plugins from /Users/orr/SbtHome/plugins
[info] Loading project definition from /Users/orr/SbtProj/project
> clean
[success] Total time: 0 s, completed Jan 31, 2013 2:46:38 PM
> reload return
[info] Loading global plugins from /Users/orr/SbtHome/plugins/project
[info] Loading global plugins from /Users/orr/SbtHome/plugins
[info] Loading project definition from /Users/orr/SbtProj/project
[info] Updating {file:/Users/orr/SbtProj/project/}default-2448b4...
[info] Resolving org.scala-sbt#precompiled-2_10_0;0.12.2 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/orr/SbtProj/project/target/scala-2.9.2/sbt-0.12/classes...
[info] Set current project to my-test-proj (in build file:/Users/orr/SbtProj/)
> 
  1. Now, after cleaning the project/ project, try to use the gen-idea command again:
> gen-idea
[info] Trying to create an Idea module my-test-proj
[info] Updating {file:/Users/orr/SbtProj/}my-test-proj...
[info] Resolving org.scala-lang#scala-library;2.9.2 ...
[info] Done updating.
[info] Resolving org.scala-lang#scala-library;2.9.2 ...
[info] Excluding folder target
[info] Created /Users/orr/SbtProj/.idea/IdeaProject.iml
[info] Created /Users/orr/SbtProj/.idea
[info] Excluding folder /Users/orr/SbtProj/target
[info] Created /Users/orr/SbtProj/.idea_modules/my-test-proj.iml
[info] Created /Users/orr/SbtProj/.idea_modules/my-test-proj-build.iml
> 

Conclusion

So there you have it – after adding a global plugin, it's tasks/commands aren't available to an existing projec which has a .scala build definition. Only reloading, cleaning and returning the plugins project for that project, makes the new tasks/commands available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment