11# BPJ (Better Print for Java)
22
3- BPJ is a Java 17+ library that makes string interpolation and prints easier.
4- It is designed to reduce boilerplate when building messages like:
5-
6- ``` java
7- BPJ . println(" Bienvenido {usuario.name}" , this );
3+ [ ![ Maven Central] ( https://img.shields.io/maven-central/v/io.github.oriontheprogrammer/bpj?logo=apachemaven&label=Maven%20Central )] ( https://central.sonatype.com/artifact/io.github.oriontheprogrammer/bpj )
4+ [ ![ Java] ( https://img.shields.io/badge/Java-17%2B-007396?logo=openjdk&logoColor=white )] ( https://openjdk.org/ )
5+ [ ![ Gradle Plugin] ( https://img.shields.io/maven-central/v/io.github.oriontheprogrammer/bpj-gradle-plugin?label=Gradle%20Plugin&logo=gradle )] ( https://central.sonatype.com/artifact/io.github.oriontheprogrammer/bpj-gradle-plugin )
6+ [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-green.svg )] ( LICENSE )
7+ [ ![ CI] ( https://img.shields.io/github/actions/workflow/status/OrionTheProgrammer/better-print-java/ci.yml?branch=main&label=CI&logo=githubactions )] ( https://github.com/OrionTheProgrammer/better-print-java/actions/workflows/ci.yml )
8+
9+ 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 ` .
10+
11+ ## Why BPJ
12+
13+ - Reduce Java boilerplate when building dynamic messages.
14+ - Keep source code readable with template-style strings.
15+ - Return interpolated strings with ` BPJ.format(...) ` .
16+ - Print interpolated text with ` BPJ.print(...) ` / ` BPJ.println(...) ` .
17+ - Choose between explicit runtime context or automatic build-time injection.
18+
19+ ## How It Works
20+
21+ ``` mermaid
22+ flowchart LR
23+ A["BPJ.println('Hello {user.name}')"] --> B{"Plugin active?"}
24+ B -->|No| C["Use explicit context overloads"]
25+ B -->|Yes| D["Build rewrites source and injects context"]
26+ C --> E["Resolved runtime output"]
27+ D --> E
828```
929
10- ## What It Is For
11-
12- - Build readable messages with placeholders (` {name} ` , ` {product.value} ` , ` {persona.getName()} ` , ` {final} ` ).
13- - Return interpolated ` String ` values with ` BPJ.format(...) ` .
14- - Print interpolated text with ` BPJ.print(...) ` and ` BPJ.println(...) ` .
15- - Use Maven or Gradle build-time transformation so one-argument BPJ calls can work in regular Java code.
16-
1730## Installation
1831
19- ### Maven (runtime + plugin manual setup )
32+ ### 1) Runtime dependency (required in all cases )
2033
2134``` xml
2235<dependency >
@@ -26,6 +39,36 @@ BPJ.println("Bienvenido {usuario.name}", this);
2639</dependency >
2740```
2841
42+ ``` groovy
43+ implementation "io.github.oriontheprogrammer:bpj:0.3.0"
44+ ```
45+
46+ ### 2) Activate automatic one-argument mode (optional but recommended)
47+
48+ #### Maven options
49+
50+ Option A (` bpj-starter-parent ` , easiest):
51+
52+ ``` xml
53+ <parent >
54+ <groupId >io.github.oriontheprogrammer</groupId >
55+ <artifactId >bpj-starter-parent</artifactId >
56+ <version >0.3.0</version >
57+ </parent >
58+ ```
59+
60+ Option B (` bpj-spring-boot-parent ` , Spring Boot friendly):
61+
62+ ``` xml
63+ <parent >
64+ <groupId >io.github.oriontheprogrammer</groupId >
65+ <artifactId >bpj-spring-boot-parent</artifactId >
66+ <version >0.3.0</version >
67+ </parent >
68+ ```
69+
70+ Option C (manual plugin, for custom parent including ` spring-boot-starter-parent ` ):
71+
2972``` xml
3073<build >
3174 <plugins >
@@ -45,9 +88,9 @@ BPJ.println("Bienvenido {usuario.name}", this);
4588</build >
4689```
4790
48- ### Gradle (runtime + plugin)
91+ #### Gradle options
4992
50- Recommended ( plugin DSL) :
93+ Recommended plugin DSL:
5194
5295``` groovy
5396// settings.gradle
@@ -75,25 +118,90 @@ dependencies {
75118}
76119```
77120
78- Legacy fallback ( ` buildscript ` + ` apply plugin ` ) is still supported.
121+ Legacy ` buildscript ` mode is still supported. See docs below .
79122
80- ## Usage
123+ ## Usage: Plugin OFF vs Plugin ON
81124
82- Activation guide:
83- - ` docs/PLUGIN_ACTIVATION_GUIDE.md `
125+ | Mode | Example | Notes |
126+ | ---| ---| ---|
127+ | Plugin OFF (explicit context) | ` BPJ.format("Hello {name}", Map.of("name", name)) ` | Always works, no source rewrite needed |
128+ | Plugin OFF (object root) | ` BPJ.format("User: {name}", this) ` | Resolves from object fields/getters |
129+ | Plugin ON (auto injection) | ` BPJ.format("Hello {name}") ` | Build plugin injects context automatically |
130+ | Plugin ON (print) | ` BPJ.println("Welcome {user.name}") ` | Clean one-argument style |
84131
85- ### Print
132+ ### Without plugin (explicit context)
86133
87134``` java
88- BPJ . println( " Hola {name} " );
89- BPJ . print( " Valor del producto: {product.value} " );
90- BPJ . print( " Nombre: {persona.getName()} " );
135+ String text = BPJ . format( " Product value: {product.value} " , Map . of( " product " , product) );
136+ String text2 = BPJ . format( " Hello {name}, age {age} " , " name " , name, " age " , age );
137+ BPJ . println( " Welcome {name} " , this );
91138```
92139
93- ### Return a String
140+ ### With plugin active (one argument)
141+
142+ ``` java
143+ BPJ . println(" Hello {name}" );
144+ BPJ . println(" Welcome {user.name}" );
145+ BPJ . println(" Method call: {user.getName()}" );
146+
147+ String text = BPJ . format(" Final price: {finalPrice}" );
148+ ```
149+
150+ ## Return ` String ` Values
151+
152+ BPJ works for returned values, not only console output:
94153
95154``` java
96155public String retornarTexto(String name, int edad) {
97- return BPJ . format(" Hola {name}, tienes {edad}" , this );
156+ return BPJ . format(" Hola {name}, tienes {edad}" );
98157}
99158```
159+
160+ Important:
161+ - The no-extra-args form above requires plugin activation.
162+ - If plugin is not active, use ` BPJ.format("Hola {name}, tienes {edad}", this) ` or explicit map/key-values.
163+
164+ ## Verify Plugin Activation
165+
166+ Maven:
167+
168+ ``` bash
169+ mvn clean compile
170+ ```
171+
172+ Check generated sources:
173+ - ` target/generated-sources/bpj `
174+
175+ Gradle:
176+
177+ ``` bash
178+ ./gradlew clean compileJava
179+ ```
180+
181+ Check generated sources:
182+ - ` build/generated/sources/bpj/main `
183+
184+ ## Update to New Versions (Maven Central)
185+
186+ 1 . Check latest published versions:
187+ - Runtime: < https://central.sonatype.com/artifact/io.github.oriontheprogrammer/bpj >
188+ - Maven plugin: < https://central.sonatype.com/artifact/io.github.oriontheprogrammer/bpj-maven-plugin >
189+ - Gradle plugin: < https://central.sonatype.com/artifact/io.github.oriontheprogrammer/bpj-gradle-plugin >
190+ 2 . Replace ` 0.3.0 ` in your ` pom.xml ` / ` build.gradle ` .
191+ 3 . Rebuild:
192+ - Maven: ` mvn -B -ntp clean verify `
193+ - Gradle: ` ./gradlew clean build `
194+
195+ ## Documentation
196+
197+ - [ API reference] ( docs/API_REFERENCE.md )
198+ - [ Plugin activation guide] ( docs/PLUGIN_ACTIVATION_GUIDE.md )
199+ - [ Maven plugin guide] ( docs/MAVEN_PLUGIN.md )
200+ - [ Gradle plugin guide] ( docs/GRADLE_PLUGIN.md )
201+ - [ Spring Boot parent guide] ( docs/SPRING_BOOT_PARENT.md )
202+
203+ ## Visual Assets
204+
205+ Badges and icons are powered by:
206+ - [ Shields.io] ( https://shields.io/ )
207+ - [ Simple Icons] ( https://simpleicons.org/ )
0 commit comments