├── .gitignore ├── LICENSE ├── CHANGELOG.markdown ├── src └── main │ └── scala │ └── JRebelPlugin.scala └── README.markdown /.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.log 3 | *.swp 4 | *~ 5 | target/ 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This software is licensed under the Apache 2 license, quoted below. 2 | 3 | Copyright 2010-2013 Joonas Javanainen 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 6 | use this file except in compliance with the License. You may obtain a copy of 7 | the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | License for the specific language governing permissions and limitations under 15 | the License. 16 | -------------------------------------------------------------------------------- /CHANGELOG.markdown: -------------------------------------------------------------------------------- 1 | # sbt-jrebel-plugin changelog 2 | 3 | ## 0.10.0 (Sep 2, 2013) 4 | 5 | First release for SBT 0.13. 6 | 7 | + Changed groupId/organization to "fi.gekkio.sbtplugins" 8 | + Releases are deployed to Maven central 9 | 10 | ## 0.9.0 (Oct 1, 2011) 11 | 12 | First release for SBT 0.9+. 13 | 14 | This version targets SBT 0.11.0. Please note that SBT 0.9+ is radically different and this plugin has been rewritten. 15 | 16 | Bug fixes: 17 | 18 | + JRebel detection works with 4.5.0 release 19 | 20 | ## 0.2.1 (Nov 23, 2010) 21 | 22 | This release fixes a minor bug. 23 | 24 | Bug fixes: 25 | 26 | + Automatic rebel.xml generation now works for JAR projects with no files in src/main/resources 27 | 28 | ## 0.2.0 (Oct 12, 2010) 29 | 30 | This release improves the plugin greatly and fixes all known bugs. 31 | 32 | New features: 33 | 34 | + Restructured project into separate JAR/WAR parts 35 | + Configurable rebel.xml -inclusion for JAR/WAR projects 36 | 37 | Bug fixes: 38 | 39 | + Nonexistent directories are no longer added to rebel.xml 40 | 41 | ## 0.1.0 (Mar 29, 2010) 42 | 43 | This is the first release. 44 | 45 | Features: 46 | 47 | + Basic rebel.xml generation for WAR projects 48 | + Generates rebel.xml by default only if SBT is run with JRebel 49 | -------------------------------------------------------------------------------- /src/main/scala/JRebelPlugin.scala: -------------------------------------------------------------------------------- 1 | package fi.gekkio.sbtplugins.jrebel 2 | 3 | import sbt._ 4 | import sbt.Keys._ 5 | import sbt.Scope.GlobalScope 6 | import scala.xml._ 7 | 8 | object JRebelPlugin extends Plugin { 9 | object jrebel { 10 | val classpath = SettingKey[Seq[File]]("jrebel-classpath") 11 | val enabled = SettingKey[Boolean]("jrebel-enabled") 12 | val rebelXml = SettingKey[File]("jrebel-rebel-xml") 13 | val webLinks = SettingKey[Seq[File]]("jrebel-web-links") 14 | } 15 | 16 | val jrebelGenerate = TaskKey[Seq[File]]("jrebel-generate") 17 | 18 | val jrebelSettings: Seq[Def.Setting[_]] = Seq[Setting[_]]( 19 | jrebel.classpath <<= Seq(Keys.classDirectory in Compile, Keys.classDirectory in Test).join, 20 | jrebel.enabled := (java.lang.Package.getPackage("com.zeroturnaround.javarebel") != null), 21 | jrebel.rebelXml <<= (resourceManaged in Compile) { _ / "rebel.xml" }, 22 | jrebel.webLinks := Seq(), 23 | jrebelGenerate <<= rebelXmlTask, 24 | resourceGenerators in Compile <+= jrebelGenerate 25 | ) 26 | 27 | private def dirXml(dir: File) = 28 | 29 | private def webLinkXml(link: File) = 30 | 31 | 32 | { dirXml(link) } 33 | 34 | 35 | 36 | private def rebelXmlTask: Def.Initialize[Task[Seq[File]]] = 37 | (jrebel.enabled, jrebel.classpath, jrebel.rebelXml, jrebel.webLinks, state) map { 38 | (enabled, classpath, rebelXml, webLinks, state) => 39 | if (!enabled) Nil 40 | else { 41 | val xml = 42 | 43 | 44 | { classpath.map(dirXml) } 45 | 46 | { 47 | webLinks.map(webLinkXml) 48 | } 49 | 50 | 51 | IO.touch(rebelXml) 52 | XML.save(rebelXml.absolutePath, xml, "UTF-8", true) 53 | 54 | state.log.info("Wrote rebel.xml to %s".format(rebelXml.absolutePath)) 55 | 56 | rebelXml :: Nil 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | sbt-jrebel-plugin 2 | ================= 3 | 4 | ## Introduction 5 | 6 | sbt-jrebel-plugin is a plugin for [Simple Build Tool](http://www.scala-sbt.org) that generates configuration files (rebel.xml) for [JRebel](http://www.zeroturnaround.com/jrebel/). A rebel.xml is not always required but is recommended because if you don't have one, JRebel cannot understand the layout of your project and might fail to reload changes. You also cannot reload changes from separate projects. 7 | 8 | **Supported SBT versions: 0.13.x** 9 | 10 | ## Features 11 | 12 | + Generates rebel.xml, so it's similar to javarebel-maven-plugin in the Maven world 13 | + Cross-project change reloading 14 | 15 | _Default behaviour_ 16 | 17 | + Disables itself if SBT isn't run with JRebel agent enabled 18 | + Writes rebel.xml as a managed resource which is automatically added to classpath *and artifacts* 19 | 20 | __You should always disable sbt-jrebel-plugin when publishing artifacts somewhere else than locally. Otherwise your artifacts will include rebel.xml files__ 21 | 22 | ## Usage 23 | 24 | **Make sure you run sbt with JRebel agent enabled** 25 | 26 | Add the plugin declaration to project/plugins.sbt: 27 | 28 | addSbtPlugin("fi.gekkio.sbtplugins" % "sbt-jrebel-plugin" % "0.10.0") 29 | 30 | Then include the plugin settings in your project definition: 31 | 32 | seq(jrebelSettings: _*) 33 | 34 | If you are using [xsbt-web-plugin](https://github.com/earldouglas/xsbt-web-plugin) and want to reload web resources, also add this: 35 | 36 | *xsbt-web-plugin >= 2.0:* 37 | 38 | jrebel.webLinks += (sourceDirectory in Compile).value / "webapp" 39 | 40 | (remove .value if using SBT <= 0.13.2) 41 | 42 | *xsbt-web-plugin >= 1.0:* 43 | 44 | jrebel.webLinks <++= webappSrc in webapp 45 | 46 | *xsbt-web-plugin <= 0.9:* 47 | 48 | jrebel.webLinks <++= webappResources in Compile 49 | 50 | ### How do I ...? 51 | 52 | #### Disable rebel.xml generation 53 | 54 | Project definition: 55 | `jrebel.enabled := false` 56 | 57 | or in SBT console: 58 | `set jrebel.enabled := false` 59 | 60 | #### Force rebel.xml generation (regardless of whether you run SBT with JRebel enabled) 61 | 62 | Project definition: 63 | `jrebel.enabled := true` 64 | 65 | or in SBT console: 66 | `set jrebel.enabled := true` 67 | 68 | ## Cross-project change reloading 69 | 70 | Let's say you have two projects, MyLib which is a library project and MyWebApp which is a webapp. These two are completely separate and differently versioned projects. If you have sbt-jrebel-plugin enabled for both projects, you can make changes in MyLib while developing MyWebApp and have them reloaded instantly. 71 | 72 | + Deploy MyLib with `sbt publish-local`. The package includes a rebel.xml file that contains the absolute paths to your MyLib project directories. 73 | + Update MyWebApp dependencies with `sbt update`. MyWebApp now uses the MyLib package that has a rebel.xml. 74 | + Run MyWebApp and enable continuous webapp compilation (for example I use `sbt jetty-run "~ prepare-webapp"`) 75 | + In a separate terminal, start continuous compilation for MyLib (for example, `sbt ~ compile`). 76 | + Change a class in MyLib 77 | + Notice that the change is visible in MyWebApp (if the change is reloadable using JRebel). Voilá! 78 | 79 | *Do not share rebel.xml files because by default they contain absolute paths which are computer-specific!* 80 | 81 | ## TODO 82 | 83 | Nothing at the moment! _Please report any bugs you might find_ 84 | --------------------------------------------------------------------------------