use specific lein-cljsbuild config in repl-launch? - clojure

Is there a way to specify only build a specific build configuration via repl-launch?
Maybe something like:
lein trampoline cljsbuild <build_config_id> repl-launch chrome
I'd like my :dev and :prod build configurations to output to the same file so that I don't have to worry about having an index-dev.html which includes cljsoutput-dev.js etc.
Currently I start my server with
lein ring server-headless 3000

I think that you can find the solution on the lein-cljsbuild repl-support page, https://github.com/emezeske/lein-cljsbuild/blob/1.0.1/doc/REPL.md#repl-launch
You can specify the repl-launch-commands as cljs-build properties
(defproject lein-cljsbuild-example "1.2.3"
:plugins [[lein-cljsbuild "1.0.1"]]
:cljsbuild {
:repl-listen-port 9000
:repl-launch-commands
{"my-launch" ["firefox" "-jsconsole" "http://localhost/my-page"]})
There is also a #cemerick/austin project very releated with this problematic that maybe can helps you too. (Browser-connected REPLs)

Related

How i can add github/local dependencies with Boot (clojure)

For instance i want to fork some existing clojar, extend it and use in my project.
How i can do this w/o pushing to clojars/maven?
Interested in both options: link to github and local path.
Thanks!
UPD
What i want is to include some existing Clojure project as dependency, similar like ruby gem allows.
Is this possible with Boot? Or i always need to compile to java?
Here is how I have setup my fork of castra on the castra-simple example for hoplon.
https://github.com/hoplon/demos/tree/master/castra-simple
open shell
git clone castra:repo
in castra dir
file: build.boot
; ...
(def +version+ "3.0.0-SNAPSHOT")
; ...
boot watch build-jar
open new shell
git clone castra-simple:repo
in castra-simple
file: boot.build
(set-env!
:dependencies
'[
;; ...
[hoplon/castra "3.0.0-SNAPSHOT"] ;;forked repo
;; ...
]
:source-paths #{"src"}
:resource-paths #{"assets"})
;; ...
(deftask dev
"Build castra-simple for local development."
[]
(comp
(serve
:handler 'app.handler/app
:reload true
:port 8000)
(watch) (speak) (hoplon) (reload) (cljs-repl) (cljs)
;;forked repo
(checkout :dependencies '[[hoplon/castra "3.0.0-SNAPSHOT"]])))
boot dev
As i figured out with Boot you can specify source-paths:
(set-env! :source-paths #{"src", "../clj-mailgun/src"})
This is the only way to add other projects into your. (adding source-code, not .jar)
There is no way to specify github link - you should clone it manually and add to :source-paths path.
Please correct me if i am missing something.

Dependencies in profiles.clj aren't loaded in lein repl

.lein/profiles.clj has dependencies as,
{:user {}
:repl {:dependencies [[org.clojure/clojure "1.4.0"]
[ring/ring "1.1.6"]]
}}
in repl
(require 'ring.adapter.jetty)
throws,
java.io.FileNotFoundException: Could not locate ring/adapter/jetty__init.class or ring/adapter/jetty.clj on classpath: (NO_SOURCE_FILE:0)
This means, ring dependency is not loaded in repl shell. Any mistakes?
Firstly, I would recommend reading https://github.com/technomancy/leiningen/blob/stable/doc/PROFILES.md as I'm not sure you are using profiles correctly. In particular, at the end it shows a way of debugging your profiles, which will show you what is going on.
Secondly, I'm not sure about "there is no project - I am running it from bash shell". If your loading jetty and using ring, you will also need code which sets handlers, routes and probably middleware. this means code files, which means a project tree. Create a basic project with lein new and run from the root of that project.
However, if you really do need to do it as you say, I would suggest you just do
{:user {:dependencies [[....]]}} as your profiles.clj as I suspect that what is happening is that lein is not loading your :repl profile. You could also try running lein with the explicit profile i.e. lein with-profile +repl repl

exclude certain clj namespaces from compilation in leiningen

I have a project that works fine using lein run. Now I want to compile it into a standalone jar using lein uberjar. However, there are a couple of source files in my src/projectname/ directory called e.g. playground.clj and stats.clj that I use for experimenting with emacs & the repl, but that I don't want to compile for the final project.
With something like make, I would specify all files that should be compiled. With clojure/leiningen, it seems, all files are compiled by default - how can I exclude files? I haven't found anything in the leiningen docs.
I am currently using :aot :all. Is this the place to change something? Again, I couldn't find detailed documentation on this.
UPDATE:
The suggestions so far haven't worked. What has worked, however, is to include all desired namespaces instead of excluding the ones that should not be compiled. E.g.:
(defproject myproject "version"
;; ...
:profiles {:uberjar {:aot [myproject.data
myproject.db
myproject.util]}})
Have a look at leiningen's sample project.clj, which describes how to use :jar-exclusions or :uberjar-exclusions to exclude arbitrary paths when creating jars (resp. uberjars).
;; Files with names matching any of these patterns will be excluded from jars.
:jar-exclusions [#"(?:^|/).svn/"]
;; Files with names matching any of these patterns will included in the jar
;; even if they'd be skipped otherwise.
:jar-inclusions [#"^\.ebextensions"]
;; Same as :jar-exclusions, but for uberjars.
:uberjar-exclusions [#"META-INF/DUMMY.SF"]
Old question, but I think I found the answer for those coming after me.
I found the answer in the link to the sample leiningen project from #amalloy's answer, except instead of :jar-exclusions I use source-paths, here.
The idea is to create two separate source directories, one for stuff you don't care to spread around and one for stuff you do:
dev-src/<your-project>/playground.clj
dev-src/<your-project>/stats.clj
src/<your-project>/<everything-else>
Then, in your project.clj, include src in source-paths normally, and include emacs-src in a special profile where your want it visible, say the usual :dev profile:
{
;; ...
:source-paths ["src"]
:profiles {
:dev {
:source-paths ["src" "dev-src"]
}
}
}
That way when you're messing around on your machine those files will be in the jar, and when you deploy to clojars or compile with uberjar they will not be included in the jar, nor compiled.
Try this (ns ^:skip-aot my-ns)
You can also do
(ns ^{:skip-aot true} my-ns
(require [...]))
Source

create multiple uberjars in leiningen

I want to create a number of uberjars with different main entrypoints from a single codebase. I see you can specify the main namespace as an argument to lein uberjar but I don't see a way to specify the resulting filename or path, so they'll just overwrite one another. Is there a way to override the output filename or path from the command line?
Or is there a better way of doing this? Have separate project files that all reference a central "library" project? If so, what would the physical structure of this look like and how to get it to build?
You can use multiple Leiningen profiles to accomplish what you are talking about.
(defproject project1 "0.1.0-SNAPSHOT"
:description "Something Amazing!"
:dependencies [[org.clojure/clojure "1.5.1"]]
:profiles {:v1 {:main project1.core1
:uberjar-name "uberjar1.jar"}
:v2 {:main project1.core2
:uberjar-name "uberjar2.jar"}
:v3 {:main project1.core3
:uberjar-name "uberjar3.jar"}})
And, you can build them with:
$ lein with-profile v1:v2:v3 uberjar
Here is an annotated reference source where you can find an option for specifying a name of your output jar or uberjar file and any other options that may be set in a project.clj file.
;;; Jar Output
;; Name of the jar file produced. Will be placed inside :target-path.
;; Including %s will splice the project version into the filename.
:jar-name "sample.jar"
;; As above, but for uberjar.
:uberjar-name "sample-standalone.jar"

What is an elegant way to set up a leiningen project that requires different dependencies based on the build platform?

In order to do some multi-platform GUI development, I have just switched from GTK + Clojure (because it looks like the Java bindings for GTK never got ported to Windows) to SWT + Clojure. So far, so good in that I have gotten an uberjar built for Linux.
The catch, though, is that I want to build an uberjar for Windows and I am trying to figure out a clean way to manage the project.clj file.
At first, I thought I would set the classpath to point to the SWT libraries and then build the uberjar. This would require that I set a classpath to the SWT libraries before running the jar, but I would likely need a launcher script, anyway. However, leiningen seems to ignore the classpath in this instance because it always reports that
Currently, project.clj looks like this for me:
(defproject alyra.mana-punk/character "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[org.eclipse/swt-gtk-linux-x86 "3.5.2"]]
:main alyra.mana-punk.character.core)
The relevant line is the org.eclipse/swt-gtk-linux-x86 line. If I want to make an uberjar for Windows, I have to depend on org.eclipse/swt-win32-win32-x86, and another one for x86-64, and so on and so forth.
My current solution is to simply create a separate branch for each build environment with a different project.clj. This seems kinda like using a semi to deliver a single gallon of milk, but I am using bazaar for version control, so branching and repeated integrations are easy. Maybe the better way is to have a project.linux.clj, project.win32.clj, etc, but I do not see any way to tell leiningen which project descriptor to use.
What are other (preferably more elegant) ways to set up such an environment?
Here's a quite elegant solution using Java system properties:
(let [properties (select-keys (into {} (System/getProperties))
["os.arch" "os.name"])
platform (apply format "%s (%s)" (vals properties))
swt (case platform
"Windows XP (x86)" '[org.eclipse/swt-win32-win32-x86 "3.5.2"]
"Linux (x86)" '[org.eclipse/swt-gtk-linux-x86 "3.5.2"])]
(defproject alyra.mana-punk/character "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
~swt]
:main alyra.mana-punk.character.core))