Skip to content

Commit 6f2d3ba

Browse files
authored
Merge pull request #3227 from ajoberstar/gradle
Support the Gradle wrapper for jack-in
2 parents f422665 + c2744a8 commit 6f2d3ba

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
- [#3226](https://github.com/clojure-emacs/cider/pull/3226): Populate completions metadata, making it possible to change the style of completion via `completion-category-override` or `completion-category-defaults`.
88
- [#2946](https://github.com/clojure-emacs/cider/issues/2946): Add custom var `cider-merge-sessions` to allow combining sessions in two different ways: Setting `cider-merge-sessions` to `'host` will merge all sessions associated with the same host within a project. Setting it to `'project` will combine all sessions of a project irrespective of their host.
9+
- Support Gradle jack-in via the Gradle wrapper, instead of just a globally installed `gradle` on the `PATH`.
910

1011
## Changes
1112

1213
* Upgrade injected `cider-nrepl` to [0.28.5](https://github.com/clojure-emacs/cider-nrepl/releases/tag/v0.28.5).
1314
* [#3200](https://github.com/clojure-emacs/cider/issues/3200): Improve cider-browse-ns interface to allow selective hiding of var types as well as grouping options. Include private vars in result list.
15+
* Changed default `cider-gradle-command` to `./gradlew` to use the Gradle wrapper
16+
* Changed default `cider-gradle-global-options` to `""` (empty, formerly `--no-daemon`)
1417

1518
## 1.4.1 (2022-05-25)
1619

cider.el

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,14 @@ By default we favor the project-specific shadow-cljs over the system-wide."
189189
:package-version '(cider . "0.17.0"))
190190

191191
(defcustom cider-gradle-command
192-
"gradle"
192+
"./gradlew"
193193
"The command used to execute Gradle."
194194
:type 'string
195195
:safe #'stringp
196196
:package-version '(cider . "0.10.0"))
197197

198198
(defcustom cider-gradle-global-options
199-
"--no-daemon"
199+
""
200200
"Command line options used to execute Gradle (e.g.: -m for dry run)."
201201
:type 'string
202202
:safe #'stringp
@@ -352,7 +352,11 @@ Throws an error if PROJECT-TYPE is unknown."
352352
('shadow-cljs (let ((parts (split-string cider-shadow-cljs-command)))
353353
(when-let* ((command (cider--resolve-command (car parts))))
354354
(mapconcat #'identity (cons command (cdr parts)) " "))))
355-
('gradle (cider--resolve-command cider-gradle-command))
355+
;; here we have to account for use of the Gradle wrapper which is
356+
;; a shell script within their project, so if they have a clearly
357+
;; relative path like "./gradlew" use locate file instead of checking
358+
;; the exec-path
359+
('gradle (cider--resolve-project-command cider-gradle-command))
356360
(_ (user-error "Unsupported project type `%S'" project-type))))
357361

358362
(defun cider-jack-in-global-options (project-type)
@@ -1652,6 +1656,14 @@ assume the command is available."
16521656
(executable-find (concat command ".bat")))))
16531657
(shell-quote-argument command)))
16541658

1659+
(defun cider--resolve-project-command (command)
1660+
"Find COMMAND in project dir or exec path (see variable `exec-path').
1661+
If COMMAND starts with ./ or ../ resolve relative to `clojure-project-dir',
1662+
otherwise resolve via `cider--resolve-command'."
1663+
(if (string-match-p "\\`\\.\\{1,2\\}/" command)
1664+
(locate-file command (list (clojure-project-dir)) '("" ".bat") 'executable)
1665+
(cider--resolve-command command)))
1666+
16551667
(defcustom cider-connection-message-fn #'cider-random-words-of-inspiration
16561668
"The function to use to generate the message displayed on connect.
16571669
When set to nil no additional message will be displayed. A good

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ wait`)
175175

176176
==== Gradle Options
177177

178-
* `cider-gradle-command` - the name of the Gradle executable (`gradle` by default)
179-
* `cider-gradle-parameters`
180-
* `cider-gradle-global-options`
178+
* `cider-gradle-command` - the name of the Gradle executable (`./gradlew` by default)
179+
* `cider-gradle-parameters` - the Gradle arguments to invoke the repl task (`clojureRepl` by default)
180+
* `cider-gradle-global-options` - these are usually global options to gradle, such as `--no-daemon` or `--configuration-cache` (empty by default)
181181

182182
==== shadow-cljs
183183

test/cider-tests.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,23 @@
525525
:to-equal
526526
"(do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :client-build) (shadow/watch :other-build) (shadow/nrepl-select :client-build))"))))
527527

528+
(describe "cider--resolve-project-command"
529+
(it "if command starts with ./ it resolves relative to clojure-project-dir"
530+
(spy-on 'locate-file :and-return-value "/project/command")
531+
(spy-on 'executable-find :and-return-value "/bin/command")
532+
(expect (cider--resolve-project-command "./command")
533+
:to-equal "/project/command"))
534+
(it "if command starts with ../ it resolves relative to clojure-project-dir"
535+
(spy-on 'locate-file :and-return-value "/project/command")
536+
(spy-on 'executable-find :and-return-value "/bin/command")
537+
(expect (cider--resolve-project-command "../command")
538+
:to-equal "/project/command"))
539+
(it "if command is bare it resolves against the exec-path"
540+
(spy-on 'locate-file :and-return-value "/project/command")
541+
(spy-on 'executable-find :and-return-value "/bin/command")
542+
(expect (cider--resolve-project-command "command")
543+
:to-equal "/bin/command")))
544+
528545
(provide 'cider-tests)
529546

530547
;;; cider-tests.el ends here

0 commit comments

Comments
 (0)