Skip to content

Commit 5d7d866

Browse files
Support adding -Djdk.attach.allowAttachSelf to jack-in params
Add `cider-enable-nrepl-jvmti-agent` customizable to control this behaviour.
1 parent 6646778 commit 5d7d866

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cider.el

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ then concatenated into the \"-M[your-aliases]:cider/nrepl\" form."
173173
:safe #'stringp
174174
:package-version '(cider . "1.1"))
175175

176-
177176
(defcustom cider-clojure-cli-global-aliases
178177
nil
179178
"Global aliases to include when jacking in with the clojure CLI.
@@ -186,7 +185,6 @@ then concatenated into the \"-M[your-aliases]:cider/nrepl\" form."
186185
:safe #'stringp
187186
:package-version '(cider . "1.14"))
188187

189-
190188
(defcustom cider-shadow-cljs-command
191189
"npx shadow-cljs"
192190
"The command used to execute shadow-cljs.
@@ -376,6 +374,13 @@ The repl dependendcies are most likely to be nREPL middlewares."
376374
:safe #'booleanp
377375
:version '(cider . "0.11.0"))
378376

377+
(defcustom cider-enable-nrepl-jvmti-agent nil
378+
"When t, add `-Djdk.attach.allowAttachSelf' to the command line arguments,
379+
so that nREPL JVMTI agent can be loaded."
380+
:type 'boolean
381+
:safe #'booleanp
382+
:version '(cider . "1.15.0"))
383+
379384
(defcustom cider-offer-to-open-cljs-app-in-browser t
380385
"When nil, do not offer to open ClojureScript apps in a browser on connect."
381386
:type 'boolean
@@ -536,7 +541,7 @@ Throws an error if PROJECT-TYPE is unknown."
536541
"List of dependencies where elements are lists of artifact name and version.")
537542
(put 'cider-jack-in-dependencies 'risky-local-variable t)
538543

539-
(defcustom cider-injected-nrepl-version "1.1.2"
544+
(defcustom cider-injected-nrepl-version "1.2.0-beta2"
540545
"The version of nREPL injected on jack-in.
541546
We inject the newest known version of nREPL just in case
542547
your version of Boot or Leiningen is bundling an older one."
@@ -813,7 +818,9 @@ removed, LEIN-PLUGINS, LEIN-MIDDLEWARES and finally PARAMS."
813818
(seq-map (lambda (middleware)
814819
(concat "update-in :middleware conj "
815820
middleware))
816-
lein-middlewares))
821+
lein-middlewares)
822+
(when cider-enable-nrepl-jvmti-agent
823+
`(,(concat "update-in :jvm-opts conj " (shell-quote-argument "-Djdk.attach.allowAttachSelf")))))
817824
" -- ")
818825
" -- "
819826
(if (not cider-enrich-classpath)
@@ -903,9 +910,10 @@ your aliases contain any mains, the cider/nrepl one will be the one used."
903910
(deps (format "{:deps {%s} :aliases {:cider/nrepl {:main-opts [%s]}}}"
904911
(string-join all-deps " ") main-opts))
905912
(deps-quoted (cider--shell-quote-argument deps command)))
906-
(format "%s-Sdeps %s -M%s:cider/nrepl%s"
913+
(format "%s%s-Sdeps %s -M%s:cider/nrepl%s"
907914
;; TODO: global-options are deprecated and should be removed in CIDER 2.0
908915
(if global-options (format "%s " global-options) "")
916+
(if cider-enable-nrepl-jvmti-agent "-J-Djdk.attach.allowAttachSelf " "")
909917
deps-quoted
910918
(cider--combined-aliases)
911919
(if params (format " %s" params) ""))))

doc/modules/ROOT/pages/basics/up_and_running.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ You can further customize the command line CIDER uses for `cider-jack-in` by
204204
modifying the some options. Those differ a bit between the various tools,
205205
so we'll examine them tool by tool.
206206

207+
==== Enabling nREPL JVMTI agent
208+
209+
Since version 1.2.0, nREPL ships together with a native JVMTI agent, so that the
210+
eval interrupts properly work on Java 20 and later. To enable the agent, the
211+
Java process should be launched with `-Djdk.attach.allowAttachSelf`. CIDER will
212+
do it automatically during jack-in if you change
213+
`cider-enable-nrepl-jvmti-agent` customizable to `t`.
214+
207215
==== Leiningen Options
208216

209217
* `cider-lein-command` - the name of the Leiningen executable (`lein` by default)

0 commit comments

Comments
 (0)