├── .gitignore ├── README.md ├── project.clj ├── src └── leiningen │ ├── hooks │ └── scalac.clj │ └── scalac.clj └── test-project ├── .gitignore ├── README.md ├── project.clj ├── scala └── Test.scala └── src └── test_project └── core.clj /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | *jar 3 | /lib/ 4 | /classes/ 5 | .lein-deps-sum 6 | /.lein-plugins/checksum 7 | /test-project/.lein-plugins/checksum 8 | target -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lein-scalac 2 | 3 | Compile Scala source from Leiningen. 4 | 5 | ## Usage 6 | 7 | Add `[lein-scalac "0.1.0"]` to `:plugins` project.clj. (Or 8 | `:dev-dependencies` on Leiningen versions earlier than 1.7.0) 9 | 10 | Set `:scala-source-paths` in project.clj, usually to "src/scala", and 11 | place your `.scala` source files in there. 12 | 13 | Run `lein scalac` to compile them to `.class` files. 14 | 15 | If you want `scalac` to run automatically, add `:prep-tasks ["scalac"]` 16 | to `project.clj` 17 | 18 | For Leiningen 1.x support, need to add `leiningen.hooks.scalac` to 19 | `:hooks` in project.clj. 20 | 21 | If you need runtime features of Scala you'll have to declare a 22 | dependency on `scala-library` like so: 23 | 24 | `:dependencies [org.scala-lang/scala-library "2.9.1"]` 25 | 26 | ## License 27 | 28 | Copyright © 2012 Phil Hagelberg and Scott Clasen 29 | 30 | Distributed under the Eclipse Public License, the same as Clojure. 31 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject lein-scalac "0.1.0" 2 | :eval-in-leiningen true 3 | :dependencies [[org.scala-lang/scala-compiler "2.9.1"] 4 | [lancet "1.0.1"]]) -------------------------------------------------------------------------------- /src/leiningen/hooks/scalac.clj: -------------------------------------------------------------------------------- 1 | (ns leiningen.hooks.scalac 2 | (:require [robert.hooke] 3 | [leiningen.compile])) 4 | 5 | ;; This is only needed in Leiningen 1.x 6 | 7 | (robert.hooke/add-hook (resolve 'leiningen.compile/prep) 8 | (fn [f project & args] 9 | ;; Don't load scalac at every lein launch. 10 | (require 'leiningen.scalac) 11 | ((resolve 'leiningen.scalac/scalac) project) 12 | (apply f project args))) -------------------------------------------------------------------------------- /src/leiningen/scalac.clj: -------------------------------------------------------------------------------- 1 | (ns leiningen.scalac 2 | (:require [lancet.core :as lancet] 3 | [leiningen.classpath :as classpath]) 4 | (:import (org.apache.tools.ant.types Path))) 5 | 6 | (defn task-props [project] 7 | (merge {:srcdir (:scala-source-path project) 8 | :destdir (:compile-path project)} 9 | (:scalac-options project))) 10 | 11 | (.addTaskDefinition lancet/ant-project "scalac" scala.tools.ant.Scalac) 12 | 13 | (lancet/define-ant-task ant-scalac scalac) 14 | 15 | (defn scalac 16 | "Compile Scala source in :scala-source-path to :compile-path. 17 | 18 | Set :scalac-options in project.clj to pass options to the Scala compiler. 19 | See http://www.scala-lang.org/node/98 for details." 20 | [project] 21 | (let [classpath (classpath/get-classpath-string project) 22 | task (doto (lancet/instantiate-task lancet/ant-project "scalac" 23 | (task-props project)) 24 | (.setClasspath (Path. lancet/ant-project classpath)))] 25 | (lancet/mkdir {:dir (:compile-path project)}) 26 | (.execute task))) 27 | -------------------------------------------------------------------------------- /test-project/.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml 2 | *jar 3 | /lib/ 4 | /classes/ 5 | .lein-deps-sum -------------------------------------------------------------------------------- /test-project/README.md: -------------------------------------------------------------------------------- 1 | # test-project 2 | 3 | I'm an app. I sure don't do much. 4 | 5 | ## Usage 6 | 7 | FIXME 8 | 9 | ## License 10 | 11 | Copyright © 2012 FIXME 12 | 13 | Distributed under the Eclipse Public License, the same as Clojure. 14 | -------------------------------------------------------------------------------- /test-project/project.clj: -------------------------------------------------------------------------------- 1 | (defproject test-project "0.1.0" 2 | :description "test project with some scala" 3 | :dependencies [[org.clojure/clojure "1.4.0"] 4 | [org.scala-lang/scala-library "2.9.1"]] 5 | :scala-source-path "scala" 6 | :plugins [[lein-scalac "0.1.0"]] 7 | :prep-tasks ["scalac"] 8 | ;; for Leiningen 1.x you need this instead: 9 | ;; :hooks [leiningen.hooks.scalac] 10 | :main test-project.core) 11 | -------------------------------------------------------------------------------- /test-project/scala/Test.scala: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | object Test { 4 | def main (args: Array[String]) { 5 | println("Hello from Scala!") 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test-project/src/test_project/core.clj: -------------------------------------------------------------------------------- 1 | (ns test-project.core) 2 | 3 | (defn -main 4 | "I don't do a whole lot." 5 | [& args] 6 | (test.Test/main (into-array String [])) 7 | (println "Hello from Clojure!")) --------------------------------------------------------------------------------