nixpkgs/pkgs/by-name/ma/maven/build-maven-package.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
2.7 KiB
Nix
Raw Normal View History

2021-10-03 18:08:18 +00:00
{ lib
, stdenv
, jdk
2021-10-03 18:08:18 +00:00
, maven
}:
{ src
2023-08-23 18:07:29 +00:00
, sourceRoot ? null
, buildOffline ? false
2024-06-02 23:29:33 +00:00
, doCheck ? true
2023-06-17 22:28:19 +00:00
, patches ? [ ]
2021-10-03 18:08:18 +00:00
, pname
, version
, mvnJdk ? jdk
, mvnHash ? ""
2023-06-17 22:28:19 +00:00
, mvnFetchExtraArgs ? { }
, mvnDepsParameters ? ""
, manualMvnArtifacts ? [ ]
2024-02-29 11:48:33 +00:00
, manualMvnSources ? [ ]
, mvnParameters ? ""
2021-10-03 18:08:18 +00:00
, ...
} @args:
# originally extracted from dbeaver
# created to allow using maven packages in the same style as rust
2023-07-31 18:20:11 +00:00
let
2024-06-02 23:29:33 +00:00
mvnSkipTests = lib.optionalString (!doCheck) "-DskipTests";
2021-10-03 18:08:18 +00:00
fetchedMavenDeps = stdenv.mkDerivation ({
name = "${pname}-${version}-maven-deps";
2023-08-23 18:07:29 +00:00
inherit src sourceRoot patches;
2021-10-03 18:08:18 +00:00
2023-06-20 09:33:57 +00:00
nativeBuildInputs = [
2021-10-03 18:08:18 +00:00
maven
] ++ args.nativeBuildInputs or [ ];
2021-10-03 18:08:18 +00:00
JAVA_HOME = mvnJdk;
2023-09-18 20:02:49 +00:00
buildPhase = ''
runHook preBuild
'' + lib.optionalString buildOffline ''
mvn de.qaware.maven:go-offline-maven-plugin:1.2.8:resolve-dependencies -Dmaven.repo.local=$out/.m2 ${mvnDepsParameters}
2023-09-18 20:02:49 +00:00
for artifactId in ${builtins.toString manualMvnArtifacts}
do
echo "downloading manual $artifactId"
mvn dependency:get -Dartifact="$artifactId" -Dmaven.repo.local=$out/.m2
done
2024-02-29 11:48:33 +00:00
for artifactId in ${builtins.toString manualMvnSources}
do
group=$(echo $artifactId | cut -d':' -f1)
artifact=$(echo $artifactId | cut -d':' -f2)
echo "downloading manual sources $artifactId"
mvn dependency:sources -DincludeGroupIds="$group" -DincludeArtifactIds="$artifact" -Dmaven.repo.local=$out/.m2
done
2023-09-18 20:02:49 +00:00
'' + lib.optionalString (!buildOffline) ''
2024-06-02 23:29:33 +00:00
mvn package -Dmaven.repo.local=$out/.m2 ${mvnSkipTests} ${mvnParameters}
2023-09-18 20:02:49 +00:00
'' + ''
runHook postBuild
'';
2021-10-03 18:08:18 +00:00
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
installPhase = ''
runHook preInstall
2023-06-20 09:33:57 +00:00
find $out -type f \( \
-name \*.lastUpdated \
-o -name resolver-status.properties \
-o -name _remote.repositories \) \
2021-10-03 18:08:18 +00:00
-delete
runHook postInstall
2021-10-03 18:08:18 +00:00
'';
# don't do any fixup
dontFixup = true;
outputHashAlgo = if mvnHash != "" then null else "sha256";
2021-10-03 18:08:18 +00:00
outputHashMode = "recursive";
outputHash = mvnHash;
} // mvnFetchExtraArgs);
2023-07-31 18:20:11 +00:00
in
stdenv.mkDerivation (builtins.removeAttrs args [ "mvnFetchExtraArgs" ] // {
inherit fetchedMavenDeps;
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
maven
];
2021-10-03 18:08:18 +00:00
JAVA_HOME = mvnJdk;
2021-10-03 18:08:18 +00:00
buildPhase = ''
runHook preBuild
mvnDeps=$(cp -dpR ${fetchedMavenDeps}/.m2 ./ && chmod +w -R .m2 && pwd)
2024-07-27 17:03:34 +00:00
runHook afterDepsSetup
2024-06-02 23:29:33 +00:00
mvn package -o -nsu "-Dmaven.repo.local=$mvnDeps/.m2" ${mvnSkipTests} ${mvnParameters}
2021-10-03 18:08:18 +00:00
runHook postBuild
'';
2023-07-31 18:20:11 +00:00
meta = args.meta or { } // {
platforms = args.meta.platforms or maven.meta.platforms;
};
})