Skip to content

JBuild is a intentionally simple, small build tool for Java.

License

Notifications You must be signed in to change notification settings

renatoathaydes/jbuild

Repository files navigation

JBuild

Actions Status

Maven Central

JBuild is a toolkit for building Java and other JVM language based projects, focussing on dependency management and application's classpath verification.

It consists of a simple CLI, so it can be used as a very handy command-line utility, but can also be used as a Java library, allowing JVM applications to manage other Java projects and dependencies themselves.

If you're looking for a full build system, have a look at jb, which is built on top of JBuild!

Features

  • fetch artifacts from file repositories.
  • fetch artifacts from HTTP repositories.
  • fetch artifacts transitively (install command).
  • specify file and HTTP repositories locations.
  • fetch and check PGP signatures (done by jb).
  • list direct dependencies of artifacts.
  • list transitive dependencies of artifacts.
  • list available versions of artifacts.
  • detect version clashes in dependency tree.
  • list artifacts licenses.
  • install artifacts in local file system (flat dir or Maven repo).
  • check completeness of classpath given jar entry-points (exclude unused code).
  • automatically find compatible set of artifacts based on jar entry-points.
  • show full call hierarchy of jar/class/method.
  • find unused jars/classes/methods, given a classpath and jar entry-points.
  • automatically prune classpath, removing unused jars.
  • compile and package Java applications.
  • generate POM (done by jb).

Non-features

JBuild does not aim to replace Gradle or Maven, but to complement them by giving Java developers a simpler and faster alternative for certain tasks, specially dependency management (both module- and code-level dependencies) and classpath verification (something which can only be done when the full classpath is known, typically when deploying a full application).

Features that fully-fledged build tools like Maven and Gradle want to have, but JBuild doesn't:

  • general task management (e.g. Gradle tasks or Maven phases).
  • plugins (JBuild can be used as a library - you don't need a JBuild plugin when you can have your own build application that uses JBuild and other JVM libraries).
  • configuration files (though JBuild may allow passing a file with CLI options in the future).
  • anything not directly related to building Java or other JVM language applications.
  • IDE integration (though JBuild makes it easy for IDEs to see the classpath).

With that said, JBuild can easily be used in a more complete build tool, which is exactly what I did with jb.

Dependency Management

JBuild currently supports a sub-set of Maven, just enough to make sure dependency resolution works as accurately as with Maven.

Here's the list of Maven tags and concepts supported by JBuild:

  • dependencies/dependency/[groupId, artifactId, version, scope, optional]
  • dependencies/dependency/exclusions
  • dependencyManagement
  • dependency version ranges
  • project coordinates/packaging/parent
  • project license
  • project properties
  • evaluate property placeholders from properties tag
  • evaluate property placeholders from XML tags (version, artifactId, groupId)
  • parent POM
  • Maven BOM (dependencyManagement imports)

As JBuild is not designed to as a Maven replacement, Maven features not related to dependency resolution (which are needed by JBuild to resolve Java artifacts), are not expected to be added to JBuild. For example, Maven profiles and system dependencies will probably never be supported by JBuild.

Code-level dependencies

JBuild can detect dependencies between Java types in a given classpath.

Currently implemented detections:

  • direct references to a Java class.
  • direct references to a Java interface.
  • direct references to a Java enum.
  • direct references to a Java type via array.
  • references to a Java type via extension (implements and extends).
  • references to a field.
  • references to a method by direct invocation.
  • references to a super-type method by virtual invocation.
  • references to a method via MethodHandle (used a lot with the stream API).
  • indirect type references via generics (if the type is actually used, it's detected by the other detections).
  • transitive code references.

CLI

------ JBuild CLI ------
Version: 0.0

Utility to build Java (JVM) applications.

Usage:
    jbuild <root-options...> <cmd> <cmd-args...> 
Root Options:
    --quiet
     -q       print only minimum output.
    --repository
     -r       Maven repository to use to locate artifacts (file location or HTTP URL).
    --working-dir
     -w       The working directory to use.
    --verbose
    -V        log verbose output.
    --version
    -v        print JBuild version and exit.
    --help
    -h        print this usage message.

Available commands:

  * compile - compiles java source code
  * deps - lists dependencies of Maven artifacts
  * doctor - finds type-safe classpath given a set of jars
  * fetch - fetches Maven artifacts
  * install - installs Maven artifacts and dependencies into a flat dir or local Maven repo
  * requirements - finds type requirements of jars and class files
  * versions - list the versions of Maven artifacts
  * help - displays this help message or help for one of the other commands

Type 'jbuild help <command>' for more information about a command.

Artifact coordinates are given in the form <orgId>:<artifactId>[:<version>][:<ext>]
If the version is omitted, the latest available version is normally used.

Examples:
  # install latest version of Guava and all its dependencies in directory 'java-libs/'
  jbuild install com.google.guava:guava

  # show all version of javax.inject on the RedHat repository
  jbuild -r https://maven.repository.redhat.com/ga/ versions javax.inject:javax.inject

  # fetch the Guava POM
  jbuild fetch com.google.guava:guava:31.0.1-jre:pom

  # compile all Java sources in 'src/' or 'src/main/java' into a jar
  # using all jars in 'java-libs/' as the classpath
  jbuild compile

Java API

javadoc

Also refer to the CLI code, jbuild.cli.Main, and the tests to learn more.

Building

The jb build tool is used to build JBuild.

jb is a small executable that embeds JBuild to provide a modern, complete Java build tool.

To install jb, get the jb tar ball and include bin/jb in your PATH.

To compile the jbuild jar build/jbuild.jar:

jb

To run unit tests.

jb -p src/test test

To run integration tests.

jb -p src/intTest test

Bootstrapping

To compile JBuild using the java and jar commands and nothing else, run the bootstrap.sh script.

The script reads the following env vars:

  • BUILD_DIR - directory into which to compile the class files.
  • JBUILD_JAR - where to create the JBuild jar.

About

JBuild is a intentionally simple, small build tool for Java.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published