jbuild 0.1.4

High-performance Java build tool supporting Maven and Gradle
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# jbuild

**Cargo for Java** - A modern, fast, and user-friendly build system for Java projects.

## The Problem

Java developers face significant friction with existing build tools:

- **Slow startup**: Maven takes 500ms+ and Gradle 1000ms+ just to start, even for simple commands
- **High memory usage**: JVM-based tools consume 200-300MB+ of RAM
- **Complex configuration**: Verbose XML (Maven) or DSL learning curve (Gradle)
- **Poor developer experience**: No simple `add dependency` command, manual XML editing required
- **Tool fragmentation**: Different commands and concepts between Maven and Gradle

**Every `mvn compile` or `gradle build` wastes seconds waiting for the JVM to start.**

## The Solution

jbuild is a **native Rust implementation** that brings the Cargo experience to Java:

| Metric | jbuild | Maven | Gradle |
|--------|--------|-------|--------|
| **Startup** | ~10ms | ~500ms | ~1000ms |
| **Memory** | ~50MB | ~200MB | ~300MB |
| **Add Dependency** | `jbuild add pkg` | Edit XML manually | Edit DSL manually |
| **Create Project** | `jbuild new app` | `mvn archetype:generate` (interactive) | `gradle init` |

## Key Advantages

1. **50x Faster Startup** - Native binary, no JVM warmup
2. **5x Less Memory** - Efficient Rust implementation
3. **Unified CLI** - Same commands for Maven and Gradle projects
4. **Modern UX** - Simple commands like `add`, `remove`, `search`, `tree`
5. **Zero Config** - Works with existing `pom.xml` or `build.gradle`
6. **Code Quality Built-in** - Integrated Checkstyle linting

## Quick Start

```bash
# Install (coming soon)
cargo install jbuild

# Create a new project
jbuild new my-app
cd my-app

# Build and run
jbuild build
jbuild run                    # Auto-detect and run main class
jbuild run --main-class com.example.App  # Specify main class
jbuild run arg1 arg2          # Pass arguments to application

# Manage dependencies
jbuild search slf4j              # Search Maven Central
jbuild add org.slf4j:slf4j-api:2.0.9
jbuild remove org.slf4j:slf4j-api
jbuild tree                      # Show dependency tree
jbuild info org.slf4j:slf4j-api  # Show package details
jbuild outdated                  # Check for outdated dependencies
jbuild update                    # Update all dependencies
```

# Code quality
jbuild lint                      # Run Checkstyle checks
jbuild test                      # Run tests
```

## Usage

### Project Management
```bash
jbuild new my-app                # Create new Maven project
jbuild new my-app -b gradle      # Create new Gradle project
jbuild new my-lib -t lib         # Create library project
jbuild init                      # Initialize in existing directory
```

### Workspace Support (Multi-Project Builds)
```bash
jbuild workspace new my-workspace     # Create new workspace
cd my-workspace
jbuild new core -t lib                # Create core library
jbuild new app                        # Create application
jbuild workspace add core             # Add projects to workspace
jbuild workspace add app
jbuild workspace list                 # List workspace members
jbuild workspace build                # Build all projects in dependency order
jbuild workspace build compile        # Build with specific goals
```

### Building & Running
```bash
jbuild build                     # Compile + test + package
jbuild compile                   # Compile only
jbuild check                     # Check code (compile without artifacts)
jbuild test                      # Run tests
jbuild run                       # Build and run main class
jbuild watch                     # Watch for changes and auto-rebuild
jbuild watch --test              # Watch and run tests on change
jbuild                       # Uses pom.xml/build.gradle or jbuild.toml (auto-converts to pom)
jbuild clean                     # Clean build outputs
```

### Dependency Management
```bash
jbuild add group:artifact              # Add dependency (auto-detects latest version)
jbuild add group:artifact:version      # Add dependency with specific version
jbuild add group:artifact --dev        # Add test dependency
jbuild remove group:artifact           # Remove dependency
jbuild tree                            # Show dependency tree
jbuild tree                            # Shows transitive dependencies
jbuild search <query>                  # Search Maven Central
jbuild info group:artifact             # Show package details and versions
jbuild outdated                        # Show outdated dependencies
jbuild update                          # Update all dependencies to latest
jbuild update group:artifact           # Update specific dependency
jbuild info group:artifact             # Show package details and versions
```

### Configuration
```bash
# Use jbuild.toml (auto-converted to pom.xml for build execution)
cat > jbuild.toml <<'EOF'
[package]
name = "my-app"
version = "0.1.0"
java = "17"

[dependencies]
"org.slf4j:slf4j-api" = "2.0.9"

[dev-dependencies]
"org.junit.jupiter:junit-jupiter" = "5.10.0"
EOF

jbuild build   # will generate pom.xml from jbuild.toml if no pom/build.gradle present
# jbuild.lock is auto-created from jbuild.toml for reproducible builds
```

### Workspace Configuration
```toml
# jbuild-workspace.toml - Workspace configuration
members = [
    "core",
    "api",
    "app"
]

default_members = [
    "core",
    "app"
]

[resolver]
version_resolution = "Highest"  # Highest, Lowest, Fail
conflict_resolution = "Highest" # Highest, Lowest, Fail

[package]
name = "my-workspace"
version = "1.0.0"
description = "Multi-project Java workspace"
```

### Code Quality
```bash
jbuild lint                      # Run Checkstyle (9 checks)
jbuild lint -c checkstyle.xml    # Use custom config
jbuild lint src/main/java        # Check specific directory
```

## Comparison: jbuild vs Maven vs Gradle

| Feature | jbuild | Maven | Gradle |
|---------|--------|-------|--------|
| **Language** | Rust | Java | Groovy/Kotlin (JVM) |
| **Startup Time** | ~10ms | ~500ms | ~1000ms |
| **Memory Usage** | ~50MB | ~200MB+ | ~300MB+ |
| **Build File** | pom.xml / build.gradle | pom.xml | build.gradle(.kts) |
| **Add Dependency** | `jbuild add` | Manual XML edit | Manual DSL edit |
| **Search Packages** | `jbuild search` |||
| **Remove Dependency** | `jbuild remove` | Manual XML edit | Manual DSL edit |
| **Dep Tree** | `jbuild tree` | `mvn dependency:tree` | `gradle dependencies` |
| **Package Info** | `jbuild info` |||
| **Check Outdated** | `jbuild outdated` |||
| **Update Dependencies** | `jbuild update` | Manual edit | Manual edit |
| **Linting** | `jbuild lint` | Plugin required | Plugin required |
| **Project Creation** | `jbuild new` | `mvn archetype:generate` | `gradle init` |
| **Multi-module** | ✅ Both systems | ✅ Reactor | ✅ Composite builds |
| **Incremental Builds** | ✅ Built-in | ✅ Plugin-based | ✅ Native |

## Project Structure

The project is organized as a **single crate** with all modules under `src/`:

- **model/**: Maven POM model, property interpolation, and model building logic
- **artifact/**: Artifact handling and coordinates
- **core/**: Core execution engine, lifecycle management, and build optimization
- **resolver/**: Dependency resolution (transitive, conflict, version range)
- **settings/**: Maven settings.xml parsing and configuration
- **plugin_api/**: Plugin API definitions and compatibility
- **compiler/**: Java compiler integration (javac invocation, classpath management)
- **packaging/**: JAR/WAR file creation and packaging
- **testing/**: Test discovery, execution, and reporting
- **cli.rs**: CLI definition (Clap structs)
- **runner/**: Command implementation logic (modularized into submodules)
- **main.rs**: CLI dispatcher (minimal entry point)

## Status

This is an ongoing project. Both Maven and Gradle support are implemented with shared infrastructure.

**Key Features Implemented:**
- ✅ Maven POM parsing and model building
- ✅ Dependency resolution (local and remote repositories)
- ✅ Plugin loading and descriptor parsing
- ✅ Plugin dependency resolution
- ✅ Java compiler integration
- ✅ Lifecycle execution framework
- ✅ Plugin execution framework (with classpath setup)
- ✅ JNI integration for Java plugin execution (optional feature)
- ✅ External Maven process fallback for plugin execution
- ✅ JAR/WAR file packaging with manifest generation
- ✅ Test discovery and execution (JUnit, TestNG)
- ✅ Test reporting
- ✅ Profile activation logic
- ✅ Property interpolation
- ✅ Model validation
- ✅ Advanced dependency resolution (version ranges, conflicts, exclusions)
- ✅ Build optimization (incremental compilation, parallel execution)
- ✅ Plugin compatibility and configuration inheritance
-**Gradle build script parsing (Groovy/Kotlin DSL)**
-**Gradle task execution (clean, compileJava, test, jar, build)**
-**Build system detection and unified CLI**
-**Gradle dependency resolution** (integrated with shared resolver)
-**Multi-project builds** (settings.gradle support)
-**Checkstyle integration** (`jbuild lint` command with 9 checks)
-**469 tests passing** (unit, checkstyle, CLI commands, integration)

See [TODO.md](TODO.md) for the current list of remaining work items and [MIGRATION.md](MIGRATION.md) for migration details.

## Example Projects

The `examples/` directory contains sample projects demonstrating jbuild capabilities:

### Maven Examples

```
examples/
├── simple-java-project/     # Single-module Maven project
│   ├── pom.xml
│   └── src/main/java/...
└── multi-module-maven/      # Multi-module Maven project
    ├── pom.xml              # Parent POM
    ├── core/                # Core utilities module
    ├── api/                 # API interfaces module
    └── app/                 # Application module
```

**Sample Maven POM (`examples/simple-java-project/pom.xml`):**
```xml
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>simple-java-project</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
```

### Gradle Examples

```
examples/
├── simple-gradle-project/   # Single-module Gradle project
│   ├── build.gradle
│   └── src/main/java/...
└── multi-module-gradle/     # Multi-module Gradle project
    ├── settings.gradle      # Project settings
    ├── build.gradle         # Root build script
    ├── core/                # Core utilities module
    ├── api/                 # API interfaces module
    └── app/                 # Application module
```

**Sample Gradle build script (`examples/simple-gradle-project/build.gradle`):**
```groovy
plugins {
    id 'java'
}

group = 'com.example'
version = '1.0.0'

sourceCompatibility = '11'
targetCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'junit:junit:4.13.2'
}
```

**Sample settings.gradle (`examples/multi-module-gradle/settings.gradle`):**
```groovy
rootProject.name = 'multi-module-gradle'

include ':core'
include ':api'
include ':app'
```

## Building

```bash
# Build without JNI (uses external Maven process for plugins)
cargo build --release

# Build with JNI support (enables direct Java class loading)
cargo build --release --features jni
```

## Running

```bash
# Modern Cargo-like commands (auto-detects build system)
jbuild build          # Compile the project
jbuild run            # Build and run main class
jbuild test           # Run tests
jbuild clean          # Clean build outputs
jbuild lint           # Check code style (Checkstyle)

# Dependency management
jbuild add org.slf4j:slf4j-api          # Add dependency (latest version)
jbuild add org.slf4j:slf4j-api:2.0.9    # Add specific version
jbuild remove org.slf4j:slf4j-api       # Remove dependency
jbuild tree                              # Show dependency tree
jbuild outdated                          # Show outdated dependencies

# Project creation
jbuild new my-app                        # Create new app project
jbuild new my-lib --template lib         # Create new library project
jbuild init                              # Initialize in existing directory

# Legacy mode (explicit build file)
jbuild --file pom.xml compile
jbuild --file build.gradle build

# Generate shell completions
jbuild completions bash > /etc/bash_completion.d/jbuild
jbuild completions zsh > ~/.zsh/completions/_jbuild
jbuild completions fish > ~/.config/fish/completions/jbuild.fish
```

### Supported Tasks/Goals

| Maven Goal | Gradle Task | Description |
|------------|-------------|-------------|
| `compile` | `compileJava` | Compile Java sources |
| `test-compile` | `compileTestJava` | Compile test sources |
| `test` | `test` | Run tests |
| `package` | `jar` | Create JAR file |
| `clean` | `clean` | Clean build outputs |
| `install` | - | Install to local repository |
| - | `build` | Full build (compile + test + jar) |

### Code Quality: `jbuild lint`

The `lint` command runs Checkstyle checks on Java source files:

```bash
# Check all Java files in src/main/java and src/test/java
jbuild lint

# Check specific files or directories
jbuild lint src/main/java
jbuild lint src/main/java/com/example/App.java

# Use custom Checkstyle configuration
jbuild lint -c checkstyle.xml
```

**Available Checks:**
- **EmptyCatchBlock** - Detects empty catch blocks
- **EmptyStatement** - Detects empty statements (standalone semicolons)
- **MissingSwitchDefault** - Detects switch statements without default case
- **MultipleVariableDeclarations** - Detects multiple variable declarations per statement
- **SimplifyBooleanReturn** - Detects boolean returns that can be simplified
- **PackageName** - Validates package naming conventions
- **TypeName** - Validates type naming conventions
- **RedundantImport** - Detects redundant imports
- **LineLength** - Detects lines exceeding maximum length (default: 120)

## Testing

The project includes comprehensive unit tests and integration tests:

```bash
# Run all tests
cargo test

# Run only unit tests
cargo test --lib

# Run integration tests
cargo test --test example_project

# Run with output
cargo test -- --nocapture
```

### Test Structure

- **Unit tests**: Located in `src/` modules with `#[test]` attributes
- **Integration tests**: Located in `tests/` directory
- **Mocks and fixtures**: `src/testing_utils.rs` provides mock implementations for testing

### Testing Utilities

The codebase provides several testing utilities in `testing_utils`:

- `MockArtifactRepository`: In-memory artifact repository for testing
- `MockDependencyResolver`: Mock dependency resolver for controlled testing
- `TestProjectBuilder`: Fluent builder for creating test projects

Example usage:

```rust
use jbuild::{MockArtifactRepository, ArtifactRepository};

#[test]
fn test_artifact_resolution() {
    let repo = MockArtifactRepository::new();
    repo.add_artifact("com.example", "lib", "1.0.0", "/path/to/lib.jar".to_string());
    
    assert!(repo.exists("com.example", "lib", "1.0.0"));
}
```

## Architecture & Design

See [ARCHITECTURE.md](ARCHITECTURE.md) for detailed architecture documentation.

The architecture is inspired by Gradle's platform-based design. See [GRADLE_LEARNINGS.md](GRADLE_LEARNINGS.md) for architectural patterns we're adopting.

### Key Design Patterns

- **Trait-based abstractions**: Core components use traits for testability
- **Builder patterns**: Complex objects use fluent builders
- **Custom error types**: Comprehensive error handling with `MavenError`
- **Dependency injection**: Supports mock implementations for testing

## License

Licensed under the Apache License, Version 2.0.