Introducing Bld: A New Pure Java Build System

RIFE2’s bld is a new build system that allows you to write your build logic in pure Java.

bld was initially created for RIFE2 web applications, but has already moved outside of that narrow focus and is now used for non-web projects also, like the RIFE2 framework itself and our URL Encoder for Java library.

We created bld because we’re not really interested in build tools. We use them because we have to, but we’d rather just get on with coding the real stuff.

bld is designed with the following principles in mind:

nothing happens without you telling it to happen
no implicit task dependencies that could turn into auto-magical behavior
managing libs yourself is fine, having that automated also, or mix and match
build logic is written in Java, with all the advantages of Java
bld is part of RIFE2, if you have the RIFE2 jar, you have the build system

Where does bld fit?

From a very high level, build tools can be organized in a matrix:

either your tool is declarative or in code
either your tool first describes a plan or immediately executes a plan

 
Declarative
Code
Describes
Immediate

Maven

 

 

Gradle
 

 

bld
 

 

Writing your build logic in the same language as your application (Java), significantly reduces the cognitive load, and taking actions immediately without having to mentally construct a described plan, makes it easier to reason about your build.

bld lets your build logic get out of the way so that you can focus on writing applications.

Designed for modern Java

bld relies on Java 17 and leverages many of the features that this version of Java provides.

Thanks to the modern language constructs, your Java build logic ends up looking very concise, is easily readable and understood by any IDE.

You automatically get support for auto-completion and javadoc documentation, and you can split your build logic into multiple files and classes when you outgrow a single file.

Here is a complete bld file for a Java Hello World application, nothing else is needed to be able to run it, test it and deploy it:

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 = “Myapp”;
mainClass = “com.example.MyappMain”;
version = version(0,1,0);

downloadSources = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
scope(test)
.include(dependency(“org.junit.jupiter”, “junit-jupiter”, version(5,9,2)))
.include(dependency(“org.junit.platform”, “junit-platform-console-standalone”, version(1,9,2)));
}

public static void main(String[] args) {
new MyappBuild().start(args);
}
}

Creating a new project

After installing bld, you can create a new Java application with the package com.example and the name myapp, by typing the following:

bld create-blank com.example myapp

The project template that is integrated into bld is used to create the complete structure of your application and the library dependencies required to compile and run it are automatically downloaded.

This is the only time that any downloads happen without you telling bld to do so.

You can now go into your project directory and for instance run it:

./bld compile run

These also work:

./bld jar
./bld uberjar
./bld clean

Java and RIFE2 powered

bld project files benefit from all the power of Java and RIFE2.

You can for instance extract logic out into classes with custom bld operations, or you can create specialized project classes that make it easy to apply common traits, or you can use the RIFE2 template engine to generate files during your build cycle, … the possibilities are endless.

Learn more

You can learn more on the RIFE2 bld wiki, or by reaching out to us on Discord or Mastodon.

The post Introducing Bld: A New Pure Java Build System appeared first on foojay.