Mastodon Follow

JDrupes Builder Logo

View GitHub Project

Overview

Requesting resources

Test projects

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 AbstractProject implements RootProject {

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

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

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