Open Source Consultant, Software Developer and System Administrator

If you are interrested in hiring a consultant for the effective use of open source software on an enterprise grade, take a look around in the About section to see, what I have to offer.

Blog and snippets

Various snippets or code parts I found useful, so I keep them here for reference.

Restrict artifact versions with gradle versions plugin

When using the Gradle Versions Plugin I sometimes want to cap/restrict versions because things do not line up properly.

E.g. with a (currently) stable Vaadin v23 project I want to stick with Springboot 2.7 (not 3.0, as this brings all the jakarta shenanigans). So you can use rejectVersionIf and look into the designated versions.

tasks.named('dependencyUpdates').configure {
    rejectVersionIf {
        // stick with Springboot 2.X until Vaadin also switches to Jakarta-packages"org.springframework.boot" && !it.candidate.version.startsWith("2.")

Sadly we don't have better means to check the versions. Doing versions via strings feels a little bit like banging stones together to make fire.

Require local Babashka scripts

When writing more involved Babashka scripts, we usually want to extract some common functionality out into library files. Yet there seems to be no established default, where Babashka is looking for those. So if you want to require a lib-namespace, you can set it up like this:

  • Create a (or lib.clj) file; if both exist, the .bb one is used; add (ns lib) to the top.
  • Add . to the class-path.

The later can be done via:

  • Run Babashka with the -cp parameter:
bb -cp .
  • Create a bb.edn file and set :paths:
{:paths ["."]}

Slightly more involved ways can be found in the project setup section of the Babashka docs

Search Maven artifacts with Babashka

Since Maven Central changed the search I had to fix my helper script. Time to try out Babashka.

#!/usr/bin/env bb
(defn artifact [{:keys [g a v latestVersion]}]
  (str g ":" a ":" (or v latestVersion)))

(defn query [q]
  (let [query-params {:start 0 :rows 50}]
    (if (str/includes? q ":")
      (let [[g a] (str/split q #":" 2)]
        (assoc query-params
               :q (str "g:" g " AND " "a:" a)
               :core "gav"))
      (assoc query-params :q q))))

(defn request [q]
  (-> (org.httpkit.client/get
        {:content-type "application/json"
         :query-params (query q)})
      (cheshire.core/parse-string true)

(assert (= 1 (count *command-line-args*)))

(let [[q] *command-line-args*]
  (->> (request q)
       (map artifact)
       (run! prn)))