nrepl server

71 views
Skip to first unread message

Dave Ray

unread,
Feb 6, 2013, 6:03:13 PM2/6/13
to cloju...@googlegroups.com
Hi,

Has anyone written any gradle tasks to start an nrepl server with the
project classpath? Kind of like what you get with 'lein repl' without
the repl.

Thanks,

Dave

Meikel Brandmeyer

unread,
Feb 7, 2013, 2:32:31 AM2/7/13
to cloju...@googlegroups.com
Hi Dave,


Am Donnerstag, 7. Februar 2013 00:03:13 UTC+1 schrieb Dave Ray:
Has anyone written any gradle tasks to start an nrepl server with the
project classpath? Kind of like what you get with 'lein repl' without
the repl.


Not that I am aware of. I did that for nailgun (for obvious reasons). Also to start something in the background you have to drop to ant at the moment, AFAIK. So you'll need a small Java driver to kick-off the server. Not tested, but should give an idea 
how this could work.

build.gradle:
souceSets { nrepl }

// Maybe not necessary?
dependencies {
    nreplCompile "org.clojure:clojure:[1.2,1.6)"
}

task runNRepl << {
    ant.java(
        classname: "your.nrepl.Driver",
        spawn: true,
        fork: true
    ) {
        classpath(
            path: project.files(
                project.sourceSets.nrepl.output,
                project.sourceSets.main.clojure.srcDirs,
                project.configurations.testRuntime,
                // Probably for nrepl and other clojure dev stuff.
                project.configurations.development
            ).asPath
        )
        ["Maybe", "some arguments for the", "driver."].each {
            arg(value: it)
        }
    }
}

src/nrepl/java/your/nrepl/Driver.java:
package your.nrepl;

import clojure.lang.RT;
import clojure.lang.Var;
import clojure.lang.Symbol;

public class Driver {
    static final Var require = RT.var("clojure.core", "require");

    public static void main(String args[]) {
        require.invoke(Symbol.intern("your.nrepl.ns"));

        final Var kickstart = RT.var("your.nrepl.ns", "starter-fn");
        kickstart.deref().applyTo(RT.seq(args));
    }
}

The nrepl starter part on the clojure side could be in your project itself (eg. when you want to keep the nrepl server in production), but you could also put it in src/nrepl/clojure in case you just want it for production. Again this is not tested. So please provide feedback should something not work out. (Note: there may be some hiccups due to clojuresque being a bit hacky at times. I'm working on cleaning these closets for the next release.)

This could be packaged into a plugin. Anyone willing to help here, please let me know!

Meikel

Dave Ray

unread,
Feb 7, 2013, 12:58:02 PM2/7/13
to cloju...@googlegroups.com
Thanks Meikel. I'm going to give this a try. When you say "This could
be packaged into a plugin", do you mean a separate Gradle plugin or as
part of Clojuresque? It seems like it would be nice if it was
supported out of the box.

Cheers,

Dave
> --
> Sie haben diese Nachricht erhalten, weil Sie der Google Groups-Gruppe
> clojuresque beigetreten sind.
> Um Ihr Abonnement für diese Gruppe zu beenden und keine E-Mails mehr von
> dieser Gruppe zu erhalten, senden Sie eine Email an
> clojuresque...@googlegroups.com.
> Weitere Optionen: https://groups.google.com/groups/opt_out
>
>

Meikel Brandmeyer

unread,
Feb 7, 2013, 2:32:11 PM2/7/13
to cloju...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Dave,

I would imagine this a part of clojuresque proper. However it would
not depend on nrepl. People would have to specify that on their own.
(Rationale: clojuresque cannot know upfront what nrepl version the
user wants to use.) Then the task would be there ready to be used.

Another possibility is a plugin under the clojuresque umbrella. I
already extracted the Clojars support into a custom plugin.
Clojuresque itself is split in “clojure” and “clojure-min”. So there
could be “clojure-min”, “clojars” and “nrepl” plugins which are all
source by the convenience “clojure” plugin.

I will be busy for the next two weeks. So I won't be able to work on
this until then.

Meikel

PS: Since contributing to my projects is somehow hard, someone writing
a third-party plugin would be also realistic it seems. However I would
like to keep things together.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRFAE7AAoJEM2sO9pIirXjvecQAIgJx1IWkcXYh7L2asY/KXoN
Enf0zvfllj0Wc5feMziZfGu3vSdzMplFalk0aZ/qUDManv+PWg3e3yGWbJjqXaVf
hYJs0NGsk6kZxPFZvnE0NuhX4A82XfXk0x9S3LFBphYmEQoztRop9pFAJEgf2jZ5
PsIc2+5PuJ0XKiLKm5hc1Aqs/GGx5hKuR2tlE47GJvtVouCwRN4a9PWDiBq/Gd/z
kj9lnVOr+3ad9QehQHA4OmlGPOagT7YaN52xUP9z5KFXPtiMyeJy284uF8X6vtms
GRd5mAHJYP2ancYHZJe7SdNdw2oV5fr5ktjWlgY3bXU+H6LKprd81mQLuDUNJBRy
AFRuZAjJ9fd2OryvIDuvlB//31Sv1qhor/6Jz4tTC4OI8qEIyT5P4Qoc0EUd/GJj
GracYcxNKVrjv3xHJe0UuULF/RhHJ0NvwLX2c/nfpyV+iejwxG0osnoF53yMFRgl
/k9Jszk+iRp4D4EYhM5c4xhav3WQIgoZF4yyPtIKXWSPrLBUkancidiuOhJfydLV
VUeyW2S+7wDjU1AB937y4SV8HCqWj+KloX0H1Zi6GaaOi/+ycRXFPiiZs0y8AA/F
JLf4yb+8mPrgD4rv8GwXwO5DPOHGzaz4bClQA7UZYXSTpeRtvTa1lGhQ1qU7Kkc1
56ZpO+K9DRc4y9f/0I2F
=pyds
-----END PGP SIGNATURE-----

Dave Ray

unread,
Feb 10, 2013, 12:33:19 AM2/10/13
to cloju...@googlegroups.com
I played around with this a bit tonight, but my meager Gradle skills
weren't strong enough to figure out how to get your example code
working.

Here's what I came up with in that does seem to work.

// Define a task that runs an nrepl server. The port is given with
the nreplPort
// property:
// gradlew nrepl -PnreplPort=9999
// or put the property in ~/.gradle/gradle.properties
configurations { nrepl }
dependencies { nrepl 'org.clojure:tools.nrepl:0.2.1' }
task nrepl(type: JavaExec) {
classpath configurations.nrepl.asPath,
project.sourceSets.main.clojure.srcDirs,
project.sourceSets.test.clojure.srcDirs,
sourceSets.main.runtimeClasspath
main = "clojure.main"
args '--eval', "(ns gradle-nrepl (:require
[clojure.tools.nrepl.server :refer (start-server stop-server)]))",
'--eval', "(println \"Starting nrepl server on port $nreplPort\")",
'--eval', "(def server (start-server :port $nreplPort))"
}

It isn't beautiful. It would be nice if I knew how to make this
reusable. Although, it's definitely an improvement over writing the
classpath to a file and hacking a lein project file to read it in to
get a repl.

Dave

Jeremiah Via

unread,
Feb 10, 2013, 1:02:14 PM2/10/13
to cloju...@googlegroups.com

This works well for me. I added

'clojure-complete:clojure-complete:0.2.2'

to my dependencies which allows for tab completion in emacs. I tried
adding it as a dependency to the nrepl configuration but that prevented
the server from starting for some reason. I'm not so proficient with
gradle to figure out the cause.

But overall this is great. Thanks!
Reply all
Reply to author
Forward
0 new messages