From 9b87a24842d7b0885848f1e510ebf7fed5d7b5fb Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Sat, 23 Nov 2024 18:01:53 +0100 Subject: [PATCH] shell.nix: Development shell with dependencies installed --- .gitignore | 7 +++++-- .idea/compiler.xml | 4 ++-- .idea/gradle.xml | 6 ++++-- .idea/misc.xml | 5 ++--- README.md | 19 +++++++++++++++++-- app/build.gradle.kts | 2 +- shell.nix | 27 +++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index 1b6985c..f72df32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ +/.idea + # Ignore Gradle project-specific cache directory -.gradle +/.gradle # Ignore Gradle build output directory -build +/build +/app/build diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b589d56..c515aca 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + - \ No newline at end of file + diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 3ced4eb..8e890ae 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,8 +4,10 @@ - \ No newline at end of file + diff --git a/.idea/misc.xml b/.idea/misc.xml index 056a56f..a29a496 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,7 @@ - - - \ No newline at end of file + + diff --git a/README.md b/README.md index 6806364..72131f6 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,17 @@ ### Setup -Check which Java toolchains can be found by Gradle: +Dependencies (JDK23, Gradle, IntelliJ) can be installed by running `nix-shell`. + +**Commandline** + +Check which Java toolchains Gradle finds: ```shell ./gradlew javaToolchains ``` -This should include version >= 17, e.g.: +This should include version >= 23, e.g.: ``` + N/A JDK 23-ga @@ -22,6 +26,17 @@ This should include version >= 17, e.g.: | Detected by: Current JVM ``` +**IntelliJ** + +When using `nix-shell`, some configuration is necessary: + +- STRG ALT SHIFT s -> SDK -> add JDK -> + - home path: /usr/lib/openjdk + - name: usr-lib-jdk +- STRG ALT s -> build tools -> gradle -> + - local installation: /usr/lib/gradle + - Gradle JVM: usr-lib-jdk + ### Tasks List all Gradle tasks which can be run: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ab822aa..71687b0 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -28,7 +28,7 @@ dependencies { // Apply a specific Java toolchain to ease working on different environments. java { toolchain { - languageVersion = JavaLanguageVersion.of(17) + languageVersion = JavaLanguageVersion.of(23) } } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..9a49d71 --- /dev/null +++ b/shell.nix @@ -0,0 +1,27 @@ +# Gradle's toolchain support does not work with IntelliJ, thus we have to use buildFHSUserEnv + +# https://discourse.nixos.org/t/how-to-create-a-development-environment-with-intellij-idea-and-openjdk/10153 +{ + pkgs ? import { + # https://github.com/NixOS/nixpkgs/issues/166220#issuecomment-1745803058 + config.allowUnfree = true; + } +}: + +let + unstable = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz) { }; + jdk = unstable.jdk23; + gradle = unstable.gradle; +in + +( + pkgs.buildFHSUserEnv + { + name = "intellij-gradle-jdk23"; + targetPkgs = pkgs_: [ + pkgs_.jetbrains.idea-ultimate + jdk + gradle + ]; + } +).env