shell.nix: Development shell with dependencies installed

This commit is contained in:
Daniel Langbein 2024-11-23 18:01:53 +01:00
parent e57ca4030d
commit 9b87a24842
7 changed files with 58 additions and 12 deletions

7
.gitignore vendored
View File

@ -1,5 +1,8 @@
/.idea
# Ignore Gradle project-specific cache directory
.gradle
/.gradle
# Ignore Gradle build output directory
build
/build
/app/build

4
.idea/compiler.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="17" />
<bytecodeTargetLevel target="23" />
</component>
</project>
</project>

6
.idea/gradle.xml generated
View File

@ -4,8 +4,10 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="gradleHome" value="/usr/lib/gradle" />
<option name="gradleJvm" value="usr-lib-jdk" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
@ -15,4 +17,4 @@
</GradleProjectSettings>
</option>
</component>
</project>
</project>

5
.idea/misc.xml generated
View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK" />
</project>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" project-jdk-name="jbr-17" project-jdk-type="JavaSDK" />
</project>

View File

@ -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:

View File

@ -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)
}
}

27
shell.nix Normal file
View File

@ -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 <nixpkgs> {
# 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