Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions packages/mvnd/build.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
let { Attrs, BuildSpec, Local, Needs, OutputBin, OutputData, Source, Test, .. } = import "minimal.ncl" in
let { target, .. } = import "config.ncl" in
let base = import "../base/build.ncl" in
let bash = import "../bash/build.ncl" in
let glibc = import "../glibc/build.ncl" in
let jdk = import "../jdk/build.ncl" in

let version = "1.0.6" in
# The Maven that mvnd 1.0.6 embeds (mvn/lib/maven-core-<v>.jar). It is NOT our
# `maven` package and moves only when mvnd releases; build.sh fails closed if
# the tarball disagrees, and the tests assert it.
let maven_version = "3.9.16" in
let dl_base = "https://github.com/apache/maven-mvnd/releases/download/%{version}" in

let { amd64_sha256, arm64_sha256 } = {
amd64_sha256 = "88fd474fd3f21b33ec1e6a75950f6abbe493d63a5e2b429475f5230b3ee6cb24",
arm64_sha256 = "e1d8071e172740ecd6a9c380938de69aafc7622218818c56e4d526cc761723c0",
}
in

{
name = "mvnd",
# Apache Maven Daemon: a GraalVM native-image client (bin/mvnd) that hands
# builds to a long-lived daemon JVM running an embedded Maven.
#
# Prebuilt, not built from source: the client is a GraalVM native image and
# we have no GraalVM / native-image package; the daemon side builds with
# Maven from Maven Central. Per-arch upstream tarballs, like packages/jdk.
build_deps = [
{ file = "build.sh" } | Local,
match {
{ arch = 'Amd64, .. } =>
{
url = "%{dl_base}/maven-mvnd-%{version}-linux-amd64.tar.gz",
sha256 = amd64_sha256,
} | Source,
{ arch = 'Arm64, .. } =>
{
url = "%{dl_base}/maven-mvnd-%{version}-linux-aarch64.tar.gz",
sha256 = arm64_sha256,
} | Source,
} target,
base,
],
runtime_deps = [
bash, # /usr/bin/mvnd wrapper, bin/mvnd.sh and the embedded Maven's scripts
glibc, # native client: libc, libdl, libpthread, librt (+ ld-linux-aarch64 on arm64)
jdk, # the daemon is a JVM process; the wrapper defaults JAVA_HOME here
],
# Not for mvnd's own build (that is offline): the abstract network dep a
# package that builds WITH mvnd inherits, as for jbang, maven, curl, go and
# uv. Resolving plugins and dependencies from Maven Central is mvnd's job;
# only a fully populated local repository with -o runs offline.
needs =
{
dns = {},
internet = {},
} | Needs,

cmd = "./build.sh",
build_args = {
include version,
include maven_version,
},

outputs = {
mvnd = { glob = "usr/bin/mvnd" } | OutputBin,
client = { glob = "usr/share/mvnd/bin/{mvnd,mvnd.sh}" } | OutputBin,
mvnd_home = { glob = "usr/share/mvnd/**", allow_executable = true } | OutputData,
},

attrs =
{
upstream_version = version,
license_spdx = "Apache-2.0",
binary_from = "https://github.com/apache/maven-mvnd/releases",
# Daemon registry and logs (default ~/.m2/mvnd) as a session state dir,
# like gradle's GRADLE_USER_HOME. The native client reads
# MVND_DAEMON_STORAGE directly. The local repository is maven's
# MAVEN_REPO_LOCAL, which the wrapper forwards (build.sh).
env_state_wiring = {
env_var = "MVND_DAEMON_STORAGE",
prefix = "mvnd",
},
source_provenance = {
category = 'GithubRepo,
owner = "apache",
repo = "maven-mvnd",
},
} | Attrs,

# Each test keeps daemon state and the local repository in its own cwd
# (HOME may not be writable) and stops the daemon at the end, so no JVM
# outlives the test. They set MVND_DAEMON_STORAGE and MAVEN_REPO_LOCAL,
# the two variables a session wires, so they also exercise the client's
# env binding and the wrapper's forwarding.
tests = {
# --version goes through the daemon: the client prints its own version,
# then starts a daemon JVM that reports the embedded Maven.
mvnd_version =
{
class = 'Standalone,
test_deps = [base],
cmds = [
["/bin/bash", "-c", "export MVND_DAEMON_STORAGE=\"$PWD/mvnd\" MAVEN_REPO_LOCAL=\"$PWD/repo\"; mvnd -B --version > out.txt 2>&1; rc=$?; mvnd --stop >/dev/null 2>&1; exit $rc"],
["/bin/bash", "-c", "grep -qF 'mvnd) %{version}' out.txt"],
["/bin/bash", "-c", "grep -qF 'Apache Maven %{maven_version}' out.txt"],
],
} | Test,

# A real build through the daemon, offline (-o): a packaging=pom project's
# `validate` phase binds no plugins, so nothing needs Maven Central.
# Anything that does (a compile, a test run) needs network; see the PR.
offline_validate =
{
class = 'Standalone,
test_deps = [base],
cmds = [
["/bin/bash", "-c", "printf '<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\\n <modelVersion>4.0.0</modelVersion>\\n <groupId>dev.minimal</groupId>\\n <artifactId>smoke</artifactId>\\n <version>1</version>\\n <packaging>pom</packaging>\\n</project>\\n' > pom.xml"],
["/bin/bash", "-c", "export MVND_DAEMON_STORAGE=\"$PWD/mvnd\" MAVEN_REPO_LOCAL=\"$PWD/repo\"; mvnd -B -o -X validate > out.txt 2>&1; rc=$?; mvnd --stop >/dev/null 2>&1; exit $rc"],
["/bin/bash", "-c", "grep -qF 'BUILD SUCCESS' out.txt || { cat out.txt; exit 1; }"],
# The daemon used the wired storage and the forwarded repository.
["/bin/bash", "-c", "ls \"$PWD/mvnd\"/*/registry.bin >/dev/null 2>&1 || ls \"$PWD/mvnd\"/registry.bin >/dev/null 2>&1 || { ls -R \"$PWD/mvnd\"; exit 1; }"],
["/bin/bash", "-c", "grep -qF \"$PWD/repo\" out.txt || { grep -i 'local repository' out.txt; exit 1; }"],
],
} | Test,
},
} | BuildSpec
46 changes: 46 additions & 0 deletions packages/mvnd/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
set -ex

case $(uname -m) in
x86_64) PLATFORM="amd64" ;;
aarch64) PLATFORM="aarch64" ;;
*) echo "unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac

DIST="maven-mvnd-${MINIMAL_ARG_VERSION}-linux-${PLATFORM}"
tar -xof "${DIST}.tar.gz"

# Fail closed if upstream changes the Maven it embeds without this package
# noticing: the version is pinned in build.ncl and asserted by the tests.
test -f "${DIST}/mvn/lib/maven-core-${MINIMAL_ARG_MAVEN_VERSION}.jar"

INSTALL="$OUTPUT_DIR/usr/share/mvnd"
mkdir -p "$OUTPUT_DIR/usr/bin" "$INSTALL"
cp -r "${DIST}"/. "$INSTALL/"

# Windows-only payload: .cmd launchers and jansi's Windows DLLs.
find "$INSTALL" -name '*.cmd' -delete
find "$INSTALL/mvn/lib/jansi-native" -mindepth 1 -maxdepth 1 -type d -name Windows -exec rm -rf {} +

# Wrapper. bin/mvnd is the GraalVM native client; it spawns the daemon, a
# JVM, from $JAVA_HOME. Default JAVA_HOME to the packaged jdk and pin
# MVND_HOME so the client finds its daemon jars and embedded Maven.
# The embedded Maven's own bin/mvn is deliberately NOT put on PATH: the
# `maven` package owns /usr/bin/mvn.
# MAVEN_REPO_LOCAL is the local repository the `maven` package wires to a
# session state dir. mvnd has no environment binding for it, so forward it
# as -Dmaven.repo.local, the way /usr/bin/mvn does: with both packages in a
# session, mvn and mvnd then share one repository instead of downloading
# everything twice. A -Dmaven.repo.local the caller passes comes later and
# still wins. (Daemon state needs no forwarding: the client reads
# MVND_DAEMON_STORAGE itself; see env_state_wiring in build.ncl.)
cat > "$OUTPUT_DIR/usr/bin/mvnd" << 'EOF'
#!/bin/sh
export JAVA_HOME="${JAVA_HOME:-/usr/lib/jvm}"
export MVND_HOME=/usr/share/mvnd
if [ -n "${MAVEN_REPO_LOCAL:-}" ]; then
exec /usr/share/mvnd/bin/mvnd "-Dmaven.repo.local=$MAVEN_REPO_LOCAL" "$@"
fi
exec /usr/share/mvnd/bin/mvnd "$@"
EOF
chmod 0755 "$OUTPUT_DIR/usr/bin/mvnd"
Loading