Using Maven, Gradle, and Bazel in LabNow AI Container Images

LabNow AI container images come pre-installed with Maven, Gradle, and Bazel build tools, accessible immediately via profile-based build arguments that invoke automated setup scripts during the CI/CD process.

The labnow-ai/lab-foundation repository provides ready-to-run Docker images that bundle a full data-science stack with Java development tools. You can pull existing images containing these build systems or customize your own using the ARG_PROFILE_JAVA build argument to select exactly which tools to include.

How Java Build Tools Are Installed

The installation process is handled by idempotent bash functions defined in the repository's setup scripts. These functions download the latest stable releases directly from official sources and wire them into the system path during image construction.

Installation Scripts in script-setup.sh

The file docker_atom/work/script-setup.sh contains three core functions that fetch and install each build tool:

  • setup_java_maven(): Queries the Apache Maven download page to retrieve the latest version, downloads the binary ZIP to /opt/maven, symlinks all mvn* binaries into /usr/bin, and verifies the installation with mvn --version.

  • setup_gradle(): Reads the Gradle releases Atom feed, filters out milestone builds to select the newest stable version, extracts the distribution to /opt/gradle, and symlinks gradle to /usr/bin.

  • setup_bazel(): Parses the Bazel releases Atom feed to obtain the latest version tag, constructs the installer script URL for the current OS/architecture, runs the installer, and cleans up the temporary script.

These functions are invoked conditionally based on build-time arguments passed to the Dockerfiles.

Profile-Based Build System

The Docker images use a profile system driven by the ARG_PROFILE_JAVA build argument. In docker_core/Dockerfile, the build logic checks this argument to determine which installer functions to execute:

ARG ARG_PROFILE_JAVA=base

RUN if [[ "$ARG_PROFILE_JAVA" == *"maven"* ]]; then \
        source /opt/utils/script-setup.sh && setup_java_maven; \
    fi && \
    if [[ "$ARG_PROFILE_JAVA" == *"gradle"* ]]; then \
        source /opt/utils/script-setup.sh && setup_gradle; \
    fi && \
    if [[ "$ARG_PROFILE_JAVA" == *"bazel"* ]]; then \
        source /opt/utils/script-setup.sh && setup_bazel; \
    fi

The base profile always installs a JDK via setup_java_jdk (defined earlier in the script), ensuring the Java runtime is present before any build tools are added. You can combine profiles using comma-separated values like base,maven,gradle,bazel.

Using Pre-Built Images with Java Build Tools

The GitHub Actions workflow .github/workflows/build-docker.yml orchestrates image builds, passing appropriate ARG_PROFILE_JAVA values for each target. You can pull these pre-built images directly from the registry.

Pull the core image with Maven and JDK included:

docker pull quay.io/labnow/core:latest

Verify the installation:

docker run --rm quay.io/labnow/core:latest mvn --version

This outputs the Maven version information, confirming that the tool is available in /usr/bin and ready for use.

Building Custom Images with Specific Tools

To create a custom image with specific combinations of Maven, Gradle, and Bazel, clone the repository and build with custom profile arguments:

git clone https://github.com/labnow-ai/lab-foundation.git
cd lab-foundation

docker build -f docker_core/Dockerfile \
  --build-arg "ARG_PROFILE_JAVA=base,maven,gradle,bazel" \
  --build-arg "ARG_PROFILE_PYTHON=base,datascience,mkl,cv,chem" \
  -t my-custom-lab:latest .

Verify all tools are present in your custom image:

docker run --rm my-custom-lab:latest bash -lc '
  java -version && \
  mvn --version && \
  gradle --version && \
  bazel version'

Running Maven, Gradle, and Bazel Inside Containers

Once inside a running container, all tools work out-of-the-box because the installers performed the necessary path configuration and symlink creation during image creation.

Start an interactive session:

docker run -it --rm my-custom-lab:latest bash

Maven Example

Create and package a new project:

mvn archetype:generate \
  -DgroupId=com.example \
  -DartifactId=myapp \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false
cd myapp
mvn package
java -jar target/myapp-1.0-SNAPSHOT.jar

Gradle Example

Initialize and build a Java application:

gradle init --type java-application
./gradlew build
java -jar build/libs/project-name.jar

Bazel Example

Set up a minimal workspace and build:

cat > WORKSPACE <<'EOF'
workspace(name = "demo")
EOF

cat > BUILD <<'EOF'
java_binary(
    name = "HelloWorld",
    srcs = ["HelloWorld.java"],
    main_class = "HelloWorld",
)
EOF

cat > HelloWorld.java <<'EOF'
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello from Bazel!");
  }
}
EOF

bazel build //:HelloWorld
./bazel-bin/HelloWorld

Summary

  • Automated Installation: The docker_atom/work/script-setup.sh file provides setup_java_maven(), setup_gradle(), and setup_bazel() functions that download the latest stable releases and install them to /opt/ with symlinks in /usr/bin.
  • Profile-Driven Builds: Use ARG_PROFILE_JAVA with comma-separated values (base,maven,gradle,bazel) in docker_core/Dockerfile to select exactly which tools to embed.
  • CI Integration: The .github/workflows/build-docker.yml workflow automates image assembly, passing build arguments that trigger the appropriate installer functions.
  • Immediate Usability: All tools are pre-configured in the environment path, allowing you to run mvn, gradle, and bazel commands immediately upon container startup without manual installation.

Frequently Asked Questions

How do I add only Maven to an existing LabNow AI image?

You cannot modify an existing pulled image to add tools, but you can build a custom image using the docker_core/Dockerfile with --build-arg "ARG_PROFILE_JAVA=base,maven". This triggers the setup_java_maven() function in docker_atom/work/script-setup.sh, installing Maven alongside the JDK.

Where are Maven, Gradle, and Bazel installed inside the container?

According to the source code in docker_atom/work/script-setup.sh, Maven installs to /opt/maven, Gradle to /opt/gradle, and Bazel via its installer script. All tools create symlinks in /usr/bin (e.g., mvn, gradle, bazel), making them available in the default system path.

Can I use these build tools with the Python data-science stack in the same container?

Yes. Pass both ARG_PROFILE_JAVA and ARG_PROFILE_PYTHON build arguments when building from docker_core/Dockerfile. For example: --build-arg "ARG_PROFILE_JAVA=base,maven,gradle" combined with --build-arg "ARG_PROFILE_PYTHON=base,datascience,mkl" creates an image with both Java build tools and Python libraries like NumPy and SciPy.

How does the CI workflow decide which images include Maven, Gradle, or Bazel?

The .github/workflows/build-docker.yml file defines build jobs that specify ARG_PROFILE_JAVA values. For instance, the core image build passes ARG_PROFILE_JAVA=base,maven (lines 68-69), while other variants might pass base only or include gradle and bazel in the comma-separated list for specialized images.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →