Skip to content

Commit c2744a8

Browse files
committed
For Gradle jack-in use wrapper by default
While Gradle does support a global install on the PATH called via "gradle" it is much more common for projects to have the Gradle wrapper in their project, which allows each project to be pinned to a specific version of Gradle. This file is either "gradlew" or "gradlew.bat" in the project root. Since this file isn't on the exec-path, I use locate-file to resolve the file relative to the clojure-project-dir, but only if the file is clearly a relative path starting "./" or "../". We still fall back to looking up on the exec-path if someone sets their cider-gradle-command back to "gradle".
1 parent c1bd60e commit c2744a8

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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

cider.el

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ 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
@@ -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)