update: apply template

This commit is contained in:
Ture Bentzin 2025-11-20 16:30:12 +00:00
commit 7adbc33487
No known key found for this signature in database
GPG Key ID: F1E670A1ED8E92CE
5 changed files with 99 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake .

24
.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

12
GNUmakefile Normal file
View File

@ -0,0 +1,12 @@
JAVA_FMT = google-java-format
JAVA_FILES = $(shell find . -name '*.java')
XML_FMT = xmlindent
XML_FILES = $(shell find . -name '*.xml')
.PHONY: fmt
fmt:
@echo "Formatting all Java files..."
@for f in $(JAVA_FILES); do \
echo " $$f"; \
$(JAVA_FMT) -i $$f; \
done

5
Main.java Normal file
View File

@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

57
flake.nix Normal file
View File

@ -0,0 +1,57 @@
{
description = "java-template";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
];
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: let
jdk = pkgs.jdk21.override {
};
buildInputs = [
jdk
];
devTools = [
pkgs.google-java-format
];
in {
devShells.default = pkgs.mkShell {
buildInputs = buildInputs ++ devTools;
};
packages = {
default = pkgs.stdenv.mkDerivation {
pname = "java-template";
version = "1.0.0";
src = ./.;
nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ];
buildPhase = ''
javac -Werror -g:none -deprecation -verbose Main.java
'';
installPhase = ''
mkdir -p $out/{bin,lib}
cp *.class $out/lib
makeWrapper ${pkgs.lib.getExe jdk} $out/bin/java-template --add-flags "-cp $out/lib/ Main"
'';
};
};
};
flake = {
};
};
}