diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0f35df..17c44fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - uses: DeLaGuardo/setup-clojure@12.1 with: cli: latest diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3c059d4..4340c69 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - uses: DeLaGuardo/setup-clojure@12.1 with: cli: latest diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5112a0e..888fc6e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - uses: DeLaGuardo/setup-clojure@12.1 with: cli: latest diff --git a/.github/workflows/vulnerabilities.yml b/.github/workflows/vulnerabilities.yml index aa97c80..228639a 100644 --- a/.github/workflows/vulnerabilities.yml +++ b/.github/workflows/vulnerabilities.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17 + java-version: 21 - uses: DeLaGuardo/setup-clojure@12.1 with: cli: latest diff --git a/deps.edn b/deps.edn index 878a8fb..3600cb3 100644 --- a/deps.edn +++ b/deps.edn @@ -25,7 +25,7 @@ io.github.clojure/tools.build {:mvn/version "0.9.6" :exclusions [org.slf4j/slf4j-nop]} com.github.pmonks/tools-convenience {:mvn/version "1.0.142"} com.github.pmonks/tools-pom {:mvn/version "1.0.127"} - com.github.pmonks/tools-licenses {:mvn/version "2.0.167"} + com.github.pmonks/tools-licenses {:mvn/version "2.0.172"} clj-kondo/clj-kondo {:mvn/version "2023.10.20"} ; Dynamic dependencies - any time any of these changes it MUST ALSO BE CHANGED IN pbr.tasks!! @@ -36,7 +36,7 @@ org.apache.logging.log4j/log4j-slf4j2-impl {:mvn/version "2.21.1"} ; SLF4J clogging bridge org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.21.1"} ; log4j1 clogging bridge ; org.slf4j/slf4j-nop {:mvn/version "2.0.9"} ; Note: used for some commands invoked as sub-processes, but can't be used here or it will shadow log4j2 - jonase/eastwood {:mvn/version "1.4.0"} + jonase/eastwood {:mvn/version "1.4.0"} ; Note: 1.4.2 uses a version of org.ow2.asm/asm that's incompatible with clj-kondo's dependent version codox/codox {:mvn/version "0.10.8"} com.github.athos/clj-check {:git/sha "518d5a1cbfcd7c952f548e6dbfcb9a4a5faf9062"} io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"} diff --git a/src/pbr/build.clj b/src/pbr/build.clj index 307cddb..faa491d 100644 --- a/src/pbr/build.clj +++ b/src/pbr/build.clj @@ -31,7 +31,6 @@ clojure -A:deps -T:build help/doc" [clojure.java.shell :as sh] [clojure.tools.build.api :as b] [tools-convenience.api :as tc] - [tools-licenses.tasks :as lic] [pbr.tasks :as pbr])) (defn- set-opts [_] (throw (ex-info "Default set-opts fn called. Did you forget to redefine it in your pbr.clj script?" {}))) @@ -41,64 +40,64 @@ clojure -A:deps -T:build help/doc" "Clean up the project." [opts] (-> opts - (set-opts) - (pbr/clean))) + set-opts + pbr/clean)) (defn check "Check the code by AOT compiling it (and throwing away the result)." [opts] (-> opts - (set-opts) - (pbr/check))) + set-opts + pbr/check)) (defn outdated "Check for outdated dependencies (using antq)." [opts] (-> opts - (set-opts) - (pbr/antq-outdated))) + set-opts + pbr/antq-outdated)) (defn upgrade "Upgrade any outdated dependencies (using antq). NOTE: does not prompt for confirmation!" [opts] (-> opts - (set-opts) - (pbr/antq-upgrade))) + set-opts + pbr/antq-upgrade)) (defn test "Run the tests." [opts] (-> opts - (set-opts) - (pbr/run-tests))) + set-opts + pbr/run-tests)) (defn nvd "Run an NVD vulnerability check" [opts] (-> opts - (set-opts) - (pbr/nvd))) + set-opts + pbr/nvd)) (defn kondo "Run the clj-kondo linter." [opts] (-> opts - (set-opts) - (pbr/kondo))) + set-opts + pbr/kondo)) (defn eastwood "Run the eastwood linter." [opts] (-> opts - (set-opts) - (pbr/eastwood))) + set-opts + pbr/eastwood)) (defn lint "Run all linters." [opts] (-> opts - (kondo) - (eastwood))) + kondo + eastwood)) (defn ci "Run the CI pipeline." @@ -110,81 +109,89 @@ clojure -A:deps -T:build help/doc" ; (try (nvd opts) (catch Exception _)) ; This is exceptionally slow, and therefore inappropriate for every CI build (lint opts))) -(defn licenses - "Attempts to list all licenses for the transitive set of dependencies of the project, as SPDX license identifiers." - [opts] - (-> opts - (set-opts) - (lic/licenses))) - -(defn check-asf-policy - "Checks this project's dependencies' licenses against the ASF's 3rd party license policy (https://www.apache.org/legal/resolved.html)." - [opts] - (-> opts - (set-opts) - (lic/check-asf-policy))) +; We do these cursed shenanigans because tools-licenses requires JDK 11+, but we want PBR to work on JDK 8+ +(if (>= (pbr/jvm-version) 11) + (do + (require 'tools-licenses.tasks) + + (eval ; I have no clue why this is necessary, unless tools.build is AOT compiling this ns or something weird... + '(defn licenses + "Attempts to list all licenses for the transitive set of dependencies of the project, as SPDX license identifiers." + [opts] + (-> opts + set-opts + tools-licenses.tasks/licenses))) + + (eval ; I have no clue why this is necessary, unless tools.build is AOT compiling this ns or something weird... + '(defn check-asf-policy + "Checks this project's dependencies' licenses against the ASF's 3rd party license policy (https://www.apache.org/legal/resolved.html)." + [opts] + (-> opts + set-opts + tools-licenses.tasks/check-asf-policy)))) + (println "⚠️ Running on an old JVM (< v11) - some functionality is unavailable.")) (defn check-release "Check that a release can be done from the current directory." [opts] (-> opts - (set-opts) - (ci) - (pbr/check-release))) + set-opts + ci + pbr/check-release)) (defn release "Release a new version of the library." [opts] (check-release opts) (-> opts - (set-opts) - (pbr/release))) + set-opts + pbr/release)) (defn pom "Generates a comprehensive pom.xml for the project." [opts] (-> opts - (set-opts) - (pbr/pom))) + set-opts + pbr/pom)) (defn jar "Generates a library JAR for the project." [opts] (-> opts - (set-opts) - (pbr/jar))) + set-opts + pbr/jar)) (defn uber "Create an uber jar." [opts] (-> opts - (set-opts) - (pbr/uber))) + set-opts + pbr/uber)) (defn uberexec "Creates an executable uber jar. NOTE: does not bundle a JRE, though one is still required." [opts] (-> opts - (set-opts) - (pbr/uberexec))) + set-opts + pbr/uberexec)) (defn install "Install the library locally e.g. so it can be tested by downstream dependencies" [opts] (-> opts - (set-opts) - (pbr/install))) + set-opts + pbr/install)) (defn deploy "Deploys the library JAR to Clojars." [opts] (-> opts - (set-opts) - (pbr/deploy))) + set-opts + pbr/deploy)) (defn docs "Generates documentation (using codox)." [opts] (-> opts - (set-opts) - (pbr/codox))) + set-opts + pbr/codox)) diff --git a/src/pbr/tasks.clj b/src/pbr/tasks.clj index cb91a70..33ec66c 100644 --- a/src/pbr/tasks.clj +++ b/src/pbr/tasks.clj @@ -126,6 +126,22 @@ (when s (s/lower-case s))) +(defn jvm-version + "Returns the version of the running JVM as an Integer. Older versions (e.g. + 1.6, 1.7, 1.8) have their minor version returned (i.e. 1.6 -> 6, 1.7 -> 7, + etc.) + Adapted from http-kit (Apache-2.0 licensed): https://github.com/http-kit/http-kit/blob/e00279f6d921efd3aad3b513ebfa42604d3cf3bd/src/org/httpkit/utils.clj#L6-L16" + [] + (let [s (System/getProperty "java.version") + dot-idx (.indexOf s ".") ; e.g. "1.6.0_23" + dash-idx (.indexOf s "-")] ; e.g. "16-ea" + (cond + ;; e.g. "1.6.0_23" + (.startsWith s "1.") (Integer/parseInt (.substring s 2 3)) + (pos? dot-idx) (Integer/parseInt (.substring s 0 dot-idx)) + (pos? dash-idx) (Integer/parseInt (.substring s 0 dash-idx)) + :else (Integer/parseInt s)))) + (defn calculate-version "Returns a calculated version number, using the provided major.minor components. Returns nil if one cannot be determined. Notes: this is a utility fn, not a task fn. This logic is specific to the author's tagging and branch naming scheme and may not work as intended in other setups." ([major minor] (calculate-version major minor nil))