Mastodon Follow

JDrupes Builder Logo

View GitHub Project

Overview

Requesting resources

Multi-project builds

Test projects

Invocation

Provider Index

Javadoc

Welcome to JDrupes Builder

JDrupes Builder (jdbld) is a build automation tool that uses Java code for its configuration and models builds as collections of resources that are produced on demand.

Here’s the source code for a sample build configuration, which will be explained in more detail below:

public class SimpleApp extends AbstractRootProject {

    public SimpleApp() {
        super(name("demo-project-simple-app"));
        generator(JavaCompiler::new).addSources(Path.of("src"), "**/*.java");
        generator(UberJarBuilder::new).addFrom(providers()
            .select(Supply)).mainClass("jdbld.demo.simpleapp.App");

        // Command arguments
        commandAlias("build").resources(of(AppJarFile.class));
    }
}

You can find the source code for this sample build configuration in the GitHub repository. To get started, copy the content of the directory test-projects/demo-project-simple-app into a directory of your choice.

In jdbld terminology, a build system is a provider of resources. It is implemented as a graph of ResourceProviders that provide Resources in response to ResourceRequests. The topmost layer of the build system’s configuration is a collection of classes that implement the special resource provider type Project. Projects provide resources by requesting them from other ResourceProviders.

Builder classes

Single project builds

In a single project build configuration, an instance of the defined project class provides all resources by requesting them from its Generators, which are another special kind of ResourceProviders.

Single project classes

A build configuration (a.k.a. project) for a simple Java application is shown below. It illustrates the objects generated by the source code of the aforementioned sample build configuration.

Simple app jar project

The project uses two generators. The first is a JavaCompiler, which provides resources of type ClassTree to the project.

        generator(JavaCompiler::new).addSources(Path.of("src"), "**/*.java");

The second generator is an UberJarGenerator.

        generator(UberJarGenerator::new).addFrom(providers().select(Supply))
            .mainClass("jdbld.demo.simpleapp.App");

This generator can provide resources of type AppJarFile. Instantiated as shown above, it uses the ClasspathElements generated by the project as input for the jar’s contents.

You might wonder why the app jar generator goes back to the project to retrieve the classpath elements. Looking at the API, we could also directly register the Java compiler with the uber jar generator via from. There are two reasons for this. First, a user might want to request the class tree from the project which would not be possible if the resources provided by the Java compiler were only used as input to the app jar generator. The second reason will become apparent when we discuss a multi-project build configuration, in which a project can provide resources from another project in addition to those obtained from its generators.

For further clarification, the diagram below shows the sequence of operations as they happen when a user requests the application jar from the project.

Simple app jar project

Start the build

To start the build, copy the shell script jdbld from the GitHub repository into the root directory of your project and make it executable:

curl -L https://raw.githubusercontent.com/mnlipp/JDrupes-Builder/refs/heads/main/jdbld -o jdbld
chmod +x jdbld

Then run the script in the root directory of your project:

./jdbld build

This will build the application jar and store it in the directory build/libs.

Note that JDrupes Builder requires Java 25 or higher. If you have an older version of Java, as default when executing java -version, you must set the environment variable JAVA_HOME to a JDK with version 25 or higher.

More details about the invocation of JDrupes Builder can be found in section invocation.