Skip to content

AndersDJohnson/maven-bin

Repository files navigation

maven-bin

Maven Central Travis Appveyor Codecov

A CLI to install & run executable libraries from Maven repositories, with automagic classpathing of dependencies, and aliases on your global path. Sort of like npm's install --global.

Features

  • With a single command, install JARs and execute their main classes.
  • Install from any Maven repo, off or on-prem, e.g. Bintray, Artifactory, Archiva, or Nexus, via settings.xml.

Use

Executing

Executing a library will be sure it and all its dependencies are downloaded, then run a class in the JAR, defaulting to its main class.

mvbn org.apache.ant:ant -help

Or the long way:

mvn me.andrz.maven:maven-bin-maven-plugin:exec "-Dartifact=org.apache.ant:ant" "-Darguments=-help"

Non-Main Classes

Non-main classes can be specified with an @... suffix on the artifact coordinates, e.g.:

mvbn org.antlr:antlr4@org.antlr.v4.gui.TestRig

Installing

Installing a library will first download as above, then create an executable script file as a shortcut to execute it.

mvbn -i org.apache.ant:ant

Or the long way:

mvn me.andrz.maven:maven-bin-maven-plugin:install "-Dartifact=org.apache.ant:ant"

Now, you'll have a command for it, e.g.:

ant--org.apache.ant--1.9.6

But you'll probably want to specify aliases.

Aliases

mvbn -i -a ant org.apache.ant:ant

Or the long way:

mvn me.andrz.maven:maven-bin-maven-plugin:install "-Dartifact=org.apache.ant:ant" "-Dalias=ant"

Now, you'll have a command for it:

ant

Classpaths

Get the classpath for an artifact:

mvbn -c org.antlr:antlr4

For example, to use when compiling:

javac -cp "$(mvbn -c org.antlr:antlr4)" MyGrammar*.java

Install

General

To install maven-bin:

1. Install Core

mvn me.andrz.maven:maven-bin-maven-plugin:installSelf

2. Add to PATH

Add ~/.mvbn/bin to your system executable PATH.

Unix (macOS, Linux, etc.)

In your shell startup script (e.g. .profile, .bashrc, .bash_profile, .zshrc), add something like:

MAVEN_BIN="${HOME}/.mvbn/bin"
if [ -d "${MAVEN_BIN}" ]; then
  export PATH="${MAVEN_BIN}:$PATH"
fi
Windows

In your PowerShell profile, add something like:

$env:Path = $env:Path + ";${env:UserProfile}\.mvbn\bin;"

Development

git clone https://github.com/AndersDJohnson/maven-bin.git
cd maven-bin
mvn install

Wishlist

  • Aliasing (default group ID and versions)
    • Add aliased command executables to global path
  • Auto-complete CLI
    • Maybe via a generic Groovy CliBuilder completion integration for Bash, zsh, PowerShell, etc.?
  • Search repos

Dev

Set log level for slf4j simple:

Just this package:

org.slf4j.simpleLogger.log.me.andrz.maven.bin=debug

Or default (all packages):

-Dorg.slf4j.simpleLogger.defaultLogLevel=debug

Research

mvn dependency:copy "-Dartifact=org.apache.ant:ant:RELEASE" "-DoutputDirectory=./bin"
mvn dependency:get "-Dartifact=org.apache.ant:ant:RELEASE"
mvn -f "C:\Users\Anders\.m2\repository\com\google\guava\guava\18.0\guava-18.0.pom" org.apache.maven.plugins:maven-dependency-plugin:2.10:build-classpath
mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:build-classpath "-Dmdep.outputFile=foo"
mvn -f .\mvn help:effective-pom

About

Install & run executable libraries from Maven repos.

Resources

License

Stars

Watchers

Forks

Packages

No packages published