2022-03-30 09:31:56 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, maven
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ src
|
2023-10-09 19:29:22 +00:00
|
|
|
, sourceRoot ? null
|
|
|
|
, buildOffline ? false
|
2023-07-15 17:15:38 +00:00
|
|
|
, patches ? [ ]
|
2022-03-30 09:31:56 +00:00
|
|
|
, pname
|
|
|
|
, version
|
2023-07-15 17:15:38 +00:00
|
|
|
, mvnHash ? ""
|
|
|
|
, mvnFetchExtraArgs ? { }
|
2023-10-09 19:29:22 +00:00
|
|
|
, mvnDepsParameters ? ""
|
|
|
|
, manualMvnArtifacts ? [ ]
|
2022-03-30 09:31:56 +00:00
|
|
|
, mvnParameters ? ""
|
|
|
|
, ...
|
|
|
|
} @args:
|
|
|
|
|
|
|
|
# originally extracted from dbeaver
|
|
|
|
# created to allow using maven packages in the same style as rust
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
let
|
2022-03-30 09:31:56 +00:00
|
|
|
fetchedMavenDeps = stdenv.mkDerivation ({
|
|
|
|
name = "${pname}-${version}-maven-deps";
|
2023-10-09 19:29:22 +00:00
|
|
|
inherit src sourceRoot patches;
|
2022-03-30 09:31:56 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
nativeBuildInputs = [
|
2022-03-30 09:31:56 +00:00
|
|
|
maven
|
|
|
|
];
|
|
|
|
|
|
|
|
buildPhase = ''
|
2023-10-09 19:29:22 +00:00
|
|
|
runHook preBuild
|
|
|
|
'' + lib.optionalString buildOffline ''
|
|
|
|
mvn dependency:go-offline -Dmaven.repo.local=$out/.m2 ${mvnDepsParameters}
|
|
|
|
|
|
|
|
for artifactId in ${builtins.toString manualMvnArtifacts}
|
|
|
|
do
|
|
|
|
echo "downloading manual $artifactId"
|
|
|
|
mvn dependency:get -Dartifact="$artifactId" -Dmaven.repo.local=$out/.m2
|
|
|
|
done
|
|
|
|
'' + lib.optionalString (!buildOffline) ''
|
2022-03-30 09:31:56 +00:00
|
|
|
mvn package -Dmaven.repo.local=$out/.m2 ${mvnParameters}
|
2023-10-09 19:29:22 +00:00
|
|
|
'' + ''
|
|
|
|
runHook postBuild
|
2022-03-30 09:31:56 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# keep only *.{pom,jar,sha1,nbm} and delete all ephemeral files with lastModified timestamps inside
|
|
|
|
installPhase = ''
|
2023-10-09 19:29:22 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
find $out -type f \( \
|
|
|
|
-name \*.lastUpdated \
|
|
|
|
-o -name resolver-status.properties \
|
|
|
|
-o -name _remote.repositories \) \
|
2022-03-30 09:31:56 +00:00
|
|
|
-delete
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
2022-03-30 09:31:56 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# don't do any fixup
|
|
|
|
dontFixup = true;
|
2023-07-15 17:15:38 +00:00
|
|
|
outputHashAlgo = if mvnHash != "" then null else "sha256";
|
2022-03-30 09:31:56 +00:00
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHash = mvnHash;
|
|
|
|
} // mvnFetchExtraArgs);
|
2023-08-04 22:07:22 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (builtins.removeAttrs args [ "mvnFetchExtraArgs" ] // {
|
|
|
|
inherit fetchedMavenDeps;
|
|
|
|
|
|
|
|
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
|
|
|
|
maven
|
|
|
|
];
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
mvnDeps=$(cp -dpR ${fetchedMavenDeps}/.m2 ./ && chmod +w -R .m2 && pwd)
|
2023-10-09 19:29:22 +00:00
|
|
|
mvn package -o -nsu "-Dmaven.repo.local=$mvnDeps/.m2" ${mvnParameters}
|
2022-03-30 09:31:56 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
2023-08-04 22:07:22 +00:00
|
|
|
|
|
|
|
meta = args.meta or { } // {
|
|
|
|
platforms = args.meta.platforms or maven.meta.platforms;
|
|
|
|
};
|
|
|
|
})
|