Skip to content

OrionTheProgrammer/better-print-java

Repository files navigation

BPJ (Better Print for Java)

Maven Central Java Gradle Plugin License: MIT CI

BPJ is a Java 17+ interpolation library that lets you write readable placeholders like {name}, {product.value} and {user.getName()} in print, println, and format.

Why BPJ

  • Reduce Java boilerplate when building dynamic messages.
  • Keep source code readable with template-style strings.
  • Return interpolated strings with BPJ.format(...).
  • Print interpolated text with BPJ.print(...) / BPJ.println(...).
  • Choose between explicit runtime context or automatic build-time injection.

How It Works

flowchart LR
  A["BPJ.println('Hello {user.name}')"] --> B{"Plugin active?"}
  B -->|No| C["Use explicit context overloads"]
  B -->|Yes| D["Build rewrites source and injects context"]
  C --> E["Resolved runtime output"]
  D --> E
Loading

Installation

1) Runtime dependency (required in all cases)

<dependency>
  <groupId>io.github.oriontheprogrammer</groupId>
  <artifactId>bpj</artifactId>
  <version>0.3.0</version>
</dependency>
implementation "io.github.oriontheprogrammer:bpj:0.3.0"

2) Activate automatic one-argument mode (optional but recommended)

Maven options

Option A (bpj-starter-parent, easiest):

<parent>
  <groupId>io.github.oriontheprogrammer</groupId>
  <artifactId>bpj-starter-parent</artifactId>
  <version>0.3.0</version>
</parent>

Option B (bpj-spring-boot-parent, Spring Boot friendly):

<parent>
  <groupId>io.github.oriontheprogrammer</groupId>
  <artifactId>bpj-spring-boot-parent</artifactId>
  <version>0.3.0</version>
</parent>

Option C (manual plugin, for custom parent including spring-boot-starter-parent):

<build>
  <plugins>
    <plugin>
      <groupId>io.github.oriontheprogrammer</groupId>
      <artifactId>bpj-maven-plugin</artifactId>
      <version>0.3.0</version>
      <executions>
        <execution>
          <goals>
            <goal>prepare</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Gradle options

Recommended plugin DSL:

// settings.gradle
pluginManagement {
  repositories {
    gradlePluginPortal()
    mavenCentral()
  }
}
// build.gradle
plugins {
  id "java"
  id "io.github.oriontheprogrammer.bpj" version "0.3.0"
}

repositories {
  mavenCentral()
}

dependencies {
  implementation "io.github.oriontheprogrammer:bpj:0.3.0"
}

Legacy buildscript mode is still supported. See docs below.

Plugin Activation (Exact Steps)

Use this section if you want one-argument BPJ calls like:

BPJ.println("Hello {name}");

to resolve values automatically.

Maven activation in 3 steps

  1. Add BPJ runtime dependency in pom.xml.
  2. Activate one Maven option:
    • Parent option: bpj-starter-parent or bpj-spring-boot-parent.
    • Manual option: add bpj-maven-plugin with goal prepare.
  3. Build through Maven:
mvn clean compile

Then verify generated files exist in:

  • target/generated-sources/bpj

Gradle activation in 4 steps

  1. Add BPJ runtime dependency in build.gradle.
  2. Add BPJ plugin id in build.gradle:
plugins {
  id "java"
  id "io.github.oriontheprogrammer.bpj" version "0.3.0"
}
  1. Ensure pluginManagement includes gradlePluginPortal() and mavenCentral() in settings.gradle.
  2. Build through Gradle:
./gradlew clean compileJava

Then verify generated files exist in:

  • build/generated/sources/bpj/main

IDE note (important)

If you run main() directly from IDE without delegated Maven/Gradle build, transformation may be skipped. Run from terminal or enable delegated build/run in your IDE.

Usage: Plugin OFF vs Plugin ON

Mode Example Notes
Plugin OFF (explicit context) BPJ.format("Hello {name}", Map.of("name", name)) Always works, no source rewrite needed
Plugin OFF (object root) BPJ.format("User: {name}", this) Resolves from object fields/getters
Plugin ON (auto injection) BPJ.format("Hello {name}") Build plugin injects context automatically
Plugin ON (print) BPJ.println("Welcome {user.name}") Clean one-argument style

Without plugin (explicit context)

String text = BPJ.format("Product value: {product.value}", Map.of("product", product));
String text2 = BPJ.format("Hello {name}, age {age}", "name", name, "age", age);
BPJ.println("Welcome {name}", this);

With plugin active (one argument)

BPJ.println("Hello {name}");
BPJ.println("Welcome {user.name}");
BPJ.println("Method call: {user.getName()}");

String text = BPJ.format("Final price: {finalPrice}");

Return String Values

BPJ works for returned values, not only console output:

public String retornarTexto(String name, int edad) {
    return BPJ.format("Hola {name}, tienes {edad}");
}

Important:

  • The no-extra-args form above requires plugin activation.
  • If plugin is not active, use BPJ.format("Hola {name}, tienes {edad}", this) or explicit map/key-values.

Verify Plugin Activation

Maven:

mvn clean compile

Check generated sources:

  • target/generated-sources/bpj

Gradle:

./gradlew clean compileJava

Check generated sources:

  • build/generated/sources/bpj/main

Update to New Versions (Maven Central)

  1. Check latest published versions:
  2. Replace 0.3.0 in your pom.xml / build.gradle.
  3. Rebuild:
    • Maven: mvn -B -ntp clean verify
    • Gradle: ./gradlew clean build

Documentation

Visual Assets

Badges and icons are powered by:

About

BPJ (Better Print for Java) is a lightweight Java 17+ library that adds Python-style string interpolation and simple print helpers for Maven projects.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages