2021-10-03 18:08:18 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2024-07-15 13:06:43 +00:00
|
|
|
, jdk
|
2021-10-03 18:08:18 +00:00
|
|
|
, maven
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ src
|
2023-08-23 18:07:29 +00:00
|
|
|
, sourceRoot ? null
|
2023-09-14 16:27:39 +00:00
|
|
|
, 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
|
2024-07-15 13:06:43 +00:00
|
|
|
, mvnJdk ? jdk
|
2023-06-20 06:18:20 +00:00
|
|
|
, mvnHash ? ""
|
2023-06-17 22:28:19 +00:00
|
|
|
, mvnFetchExtraArgs ? { }
|
2023-09-14 11:22:59 +00:00
|
|
|
, mvnDepsParameters ? ""
|
2023-09-15 08:02:05 +00:00
|
|
|
, manualMvnArtifacts ? [ ]
|
2024-02-29 11:48:33 +00:00
|
|
|
, manualMvnSources ? [ ]
|
2021-12-13 16:55:07 +00:00
|
|
|
, 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
|
2024-04-16 09:01:22 +00:00
|
|
|
] ++ args.nativeBuildInputs or [ ];
|
2021-10-03 18:08:18 +00:00
|
|
|
|
2024-07-15 13:06:43 +00:00
|
|
|
JAVA_HOME = mvnJdk;
|
|
|
|
|
2023-09-18 20:02:49 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
'' + lib.optionalString buildOffline ''
|
2023-11-14 11:12:18 +00:00
|
|
|
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 = ''
|
2023-08-19 18:04:57 +00:00
|
|
|
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
|
2023-08-19 18:04:57 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
2021-10-03 18:08:18 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# don't do any fixup
|
|
|
|
dontFixup = true;
|
2023-06-20 06:18:20 +00:00
|
|
|
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
|
|
|
|
2024-07-12 14:19:03 +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;
|
|
|
|
};
|
|
|
|
})
|