bld Build Tool

repository·main·Indexed 43 days ago

https://github.com/rife2/bld

A Java-based build tool that replaces XML or DSL-based systems like Maven and Gradle with pure Java code. It provides full IDE support, dependency management, and native support for modern deployment formats including modules, jmod, jlink, and jpackage. Version 3.0 introduces support for the Model Context Protocol (MCP) to allow AI coding agents to interact with the build process.

Tokens
2.3K
Snippets
15
Records
16
Agent score
56%

What's inside bld

  1. What is bld?

    main

    bld is a build tool that allows you to write your build logic in pure Java. Unlike Maven (XML) or Gradle (Groovy/Kotlin), bld is ordinary Java code that runs directly, providing full IDE support (auto-completion, refactoring) and the ability to use the standard Java debugger (breakpoints, watches) on your build logic.

    Key principles:

    • Tasks are explicit and API-defined; no auto-magical behavior.
    • Build logic is written in Java, allowing it to be split into multiple files/classes.
    • Distributed as a single JAR.
    • Supports modern Java deployment (modules, jmod, jlink, jpackage).
  2. Define a bld project in Java

    main

    A bld project is defined by extending the rife.bld.Project class. You configure project metadata (package, name, version, main class) and dependencies within the constructor.

    Dependencies can be defined using the dependency(group, artifact, version) helper or via a colon-separated string format "group:artifact:version".

    package com.example;
    
    import rife.bld.Project;
    import java.util.List;
    import static rife.bld.dependencies.Repository.*;
    import static rife.bld.dependencies.Scope.*;
    
    public class MyAppBuild extends Project {
        public MyAppBuild() {
            pkg = "com.example";
            name = "my-app";
            mainClass = "com.example.MyApp";
            version = version(0,1,0);
    
            downloadSources = true;
            repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
            scope(test)
                .include(dependency("org.junit.jupiter", "junit-jupiter", version(6,1,3)))
                .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(6,1,3)));
        }
    
        public static void main(String[] args) {
            new MyAppBuild().start(args);
        }
    }
  3. Install bld

    main

    You can install bld using several methods depending on your environment:

    Homebrew (macOS/Linux):

    brew install rife2/tools/bld

    SDKMAN!:

    sdk install bld

    JBang:

    jbang com.uwyn.rife2:bld:3.0.1

    You can also run it directly from its JAR file.

    brew install rife2/tools/bld
    # or
    sdk install bld
    # or
    jbang com.uwyn.rife2:bld:3.0.1
  4. Create a new bld project

    main

    To quickly scaffold a new project, use the following one-liners:

    macOS/Linux:

    bash -c "$(curl -fsSL https://rife2.com/bld/create.sh)"

    Windows (PowerShell):

    irm https://rife2.com/bld/create.ps1 | iex
    bash -c "$(curl -fsSL https://rife2.com/bld/create.sh)"
    # or on Windows
    irm https://rife2.com/bld/create.ps1 | iex
  5. Use bld with AI agents (MCP)

    main

    Since version 3.0, bld supports the Model Context Protocol (MCP), allowing AI coding agents to interact with your build via a structured interface. This provides agents with streamed command output and execution metadata for compiling, testing, and running projects.

    To register your project with an agent, use the mcp install command:

    ./bld mcp install         # register the project with Claude Code
    ./bld mcp install cursor  # register with Cursor
    ./bld mcp install vscode  # register with VS Code
  6. How extension classpaths are resolved

    main

    In bld, extension declarations are managed separately from project dependencies. While project dependencies are declared in the build file's Java code, extension declarations live in the wrapper properties on disk.

    ExtensionClasspath is responsible for reading these wrapper properties and resolving the classpath JARs for a specific dependency within the extensions. It uses a BldCache to ensure that if the extension declarations (repositories, extensions, and version overrides) haven't changed, it can quickly retrieve cached JARs instead of re-resolving the entire dependency tree.

    Key behaviors:

    • Isolation: Extension declarations are read via the Wrapper to ensure consistency between the wrapper and the build process.
    • Caching: The resolution process is fingerprinted based on the repositories, extensions, and version overrides. If these change, the cache is considered stale.
    • Scope: When resolving dependencies, it considers both Scope.compile and Scope.runtime scopes.
    // Note: ExtensionClasspath is an internal class used by the build system to resolve extension JARs.
    // It is not intended to be instantiated directly by end-users.
  7. Resolve extension classpath JARs for a dependency

    main

    To obtain the list of JAR files required for a specific dependency within the extensions, the system uses the classpathJars method. This method performs the following steps:

    1. Checks the BldCache using a hash of the current repositories, extensions, and version overrides.
    2. If a valid cache exists for the given coordinate, it returns the cached files.
    3. If no cache is valid, it uses a ParallelDependencyResolver to resolve all extension dependencies for Scope.compile and Scope.runtime.
    4. It then uses a DependencyResolver to find all transitive dependencies for the specific requested dependency.
    5. Finally, it transfers the files to the libBldDirectory and updates the cache.

    Parameters:

    • dependency: The Dependency object representing the target extension dependency.
    • coordinate: A string representation of the dependency's coordinate (used for cache lookups).

    Throws:

    • IllegalArgumentException: If the requested coordinate is not part of the project's extensions.
    // Conceptual usage within the bld build engine:
    List<File> jars = extensionClasspath.classpathJars(dependency, "group:artifact:version");
  8. Use the bld CLI commands

    main

    The bld tool is available as an executable JAR. When running the JAR, you can invoke several commands to manage project creation, upgrades, and version information. Each command is associated with a specific operation (e.g., create, upgrade, version).

    # Example of running the bld CLI (assuming the jar is named bld.jar)
    java -jar bld.jar create
    java -jar bld.jar create-app
    java -jar bld.jar upgrade
    java -jar bld.jar version