• Stars
    star
    218
  • Rank 180,713 (Top 4 %)
  • Language
    Groovy
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The gradle-one-jar project is a Gradle plugin that uses One-JAR, a specialised Class-Loader written by Simon Tuffs (http://one-jar.sourceforge.net/), for building self-contained executable jars that include all dependencies.

What is this?

This plugin rolls up your current project's jar and all of its dependencies into the the layout expected by One-JAR, producing a single runnable fat-jar, similar to the following:

my-awesome-thing-1.2.3-standalone.jar
|
+---- com
|   +---- simontuffs
|       +---- onejar
|           +---- Boot.class
|           +---- (etc., etc.)
|           +---- OneJarURLConnection.class
+---- doc
|   +---- one-jar-license.txt
+---- lib
|   +---- other-cool-lib-1.7.jar
|   +---- some-cool-lib-2.5.jar
+---- main
|   +-- main.jar
+---- META-INF
|   +---- MANIFEST.MF
+---- OneJar.class
+---- .version

You can read more about the layout of a One-JAR archive from the official site here.

##Quick Start First, you'll want to add the plugin to your build, as in:

apply plugin: 'gradle-one-jar'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.github.rholder:gradle-one-jar:1.0.4'
    }
}

Then, at a minimum, the configuration expects to find a custom 'mainClass' when adding your own task, as in:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
}

Then you can run the task with:

gradle awesomeFunJar

The end result will be a new build artifact with the standalone classifier that should be suitable for publishing to a repository, etc. via:

artifacts {
    archives awesomeFunJar
}

If you don't like the name of the final artifact, you can change it just like any other Gradle Jar task with:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    archiveName = 'koala.jar'
}

##Advanced Features The current incarnation of the gradle-one-jar plugin exists as a highly configurable Gradle task implementation built as an extension of the built-in Jar task. The following is a non-exhaustive list of some of the more advanced features that the plugin can perform to meet the varying needs of deploying standardized artifacts.

###Selectable One-JAR version By default, the one-jar-boot version used is the stable one-jar-boot-0.97.jar which is available from the One-JAR homepage (last updated 2012-08-15). However, if you'd prefer to use the latest development version one-jar-boot-0.98.jar (last updated 2010-08-25) then you can do so with the following:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    useStable = false
}

###Bring your own One-JAR version You can also use your own customized version of a one-jar-boot jar by using the oneJarConfiguration setting, as in the following that assumes your root project directory contains the jar at custom-boot/one-jar-boot-0.97.2-custom.jar:

configurations {
    oneJarLib
}

dependencies {
    oneJarLib files('custom-boot/one-jar-boot-0.97.2-custom.jar')
}

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    useStable = false
    oneJarConfiguration = configurations.oneJarLib
}

###Use custom configuration for dependencies By default, the plugin uses the current project's runtime configuration to resolve which dependencies are to be included in the final One-JAR archive. If you would rather use your own custom configuration, you can set it as follows in the task:

// add your own configuration
configurations {
    fatJarBuild
}

// declare dependencies for this configuration
dependencies {
    // only for compile
    compile 'org.slf4j:slf4j-api:1.7.2'

    // dependencies in fat jar
    fatJarBuild 'org.slf4j:slf4j-api:1.7.2'
    fatJarBuild 'org.slf4j:slf4j-simple:1.7.2'
}

// override target configuration
task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    targetConfiguration = configurations.fatJarBuild
}

###Custom MANIFEST.MF entries By default, the MANIFEST.MF added to the final One-JAR archive contains only the bare minimum number of attributes expected for one-jar-boot to behave correctly. You can add your own custom attributes to the manifest property of a OneJar task just like a Jar task, such as in:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    manifest {
        attributes 'Timestamp': String.valueOf(System.currentTimeMillis())
        attributes 'ContainsXML': 'No'
    }
}

###Merge base Jar task MANIFEST.MF entries If you just want all of the MANIFEST.MF entries that are present in your project's Jar task to be merged with the default entries needed for one-jar-boot in the final archive, then you can do so with:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    mergeManifestFromJar = true
}

###Add your own custom root MANIFEST.MF If you just want total control over the MANIFEST.MF being used in the final One-JAR archive, you can override the MANIFEST.MF entry and instead provide your own custom manifest file with the following:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    manifestFile = file('custom/MY-CUSTOM-MANIFEST.MF')
}

You should note however, that if you decide to do this, you'll need to provide the entries that are expected by one-jar-boot yourself:

Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: com.github.rholder.awesome.MyAwesomeMain
One-Jar-Show-Expand: false
One-Jar-Confirm-Expand: false
Created-By: rholder

###Add native libraries Files added to the /binlib directory within an archive get expanded to a temporary directory on startup, and the One-JAR JarClassLoader loads them automatically. To get your own native library files included in your archive, try something like this:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    binLib = files('libFoo.so')
}

###Add any files to the root archive If you just want to be able to drop arbitrary files into the root of the generated archive, then you can specify a directory (which will also include its children) to be copied over the top of the the existing files with:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    additionalDir = file('someDirFilledWithGoodies')
}

###Framework ClassLoader customizations Spring, Guice, and even JavaFX's FXML make certain assumptions about class loading that may not hold when bundling projects in a One-JAR archive. The workaround for these cases is documented here. In order to enable this functionality in the plugin, you can simply add one of the included factories to the manifest, as in:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    manifest {
        attributes 'One-Jar-URL-Factory': 'com.simontuffs.onejar.JarClassLoader$OneJarURLFactory'
    }
}

###Override the base Jar task By default, the current project's Jar task (which is made available when applying the java plugin and exposed as jar) is where a OneJar task pulls its raw compiled class and resource information to create the main/main.jar entry in the final One-JAR archive. However, it is possible to override this default with:

task awesomeFunJar(type: OneJar) {
    mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
    baseJar = someOtherJarTask
}

I'd consider this experimental functionality. If you find yourself needing to do this for some reason, you might also consider just setting up a multi-module Gradle project with a nearly empty One-JAR creator project (which would in turn create a nearly empty main/main.jar). This way you could create One-JAR archives with custom configurations, mainClass, etc., by simply creating separate OneJar tasks that were dependent on your other modules without having to worry about customizations for specific independent Jar configurations since they could be made to explicitly include whichever build was necessary.

##Building from source The gradle-one-jar build plugin uses a Gradle-based build system. In the instructions below, ./gradlew is invoked from the root of the source tree and serves as a cross-platform, self-contained bootstrap mechanism for the build. The only prerequisites are Git and JDK 1.6+.

check out sources

git clone git://github.com/rholder/gradle-one-jar.git

compile and test, build all jars

./gradlew build

install all jars into your local Maven cache

./gradlew install

##License The gradle-one-jar build plugin is released under version 2.0 of the Apache License. Distributions built with this plugin are subject to the terms set forth here. The One-JAR license is a BSD-style license. Compliance with this license is assured by including the one-jar-license.txt file in the One-JAR archive, which this plugin does automatically.

##Contributors

  • Jochen Schalanda (joschi)
  • Christian S. (squiddle)
  • Ben Manes (ben-manes)
  • Adam Walczak (walec51)

More Repositories

1

retrying

Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.
Python
1,910
star
2

guava-retrying

This is a small extension to Google's Guava library to allow for the creation of configurable retrying strategies for an arbitrary function call, such as something that talks to a remote service with flaky uptime.
Java
1,427
star
3

gradle-view

The Gradle View IntelliJ IDEA plugin shows a split tree rollup of the dependencies for each Gradle configuration in use by a project.
Java
179
star
4

csv2es

Load a CSV (or TSV) file into an Elasticsearch instance
Python
62
star
5

fauxflake

Fauxflake is an easily embeddable, decentralized, k-ordered unique ID generator.
Java
41
star
6

snowball-stemmer

This is a repackaging of a version of the snowball-stemmer found at http://snowball.tartarus.org/ so that it's available on Maven Central.
Java
19
star
7

nilsimsa

This module contains an implementation of the Nilsimsa locality-sensitive hashing algorithm in Java.
Java
18
star
8

debinate

Roll up your projects into little standalone Debian packages.
Shell
14
star
9

gradle-autojar

The gradle-autojar project is a Gradle plugin that uses Autojar, a specialized jar archive minimizer written by Bernd Eggink (http://autojar.sourceforge.net/), for building self-contained executable jars that include only those dependencies that are actually used.
Groovy
14
star
10

esthree

An S3 client that just works
Java
8
star
11

i3status-title-on-bar

Inject the active window title into the output of i3status.
Go
8
star
12

sshuttle-binary

This is a single-binary package of sshuttle.
Python
7
star
13

jvm-loop-unswitching-bug

Cause the JVM to produce a segmentation fault from org.apache.http.impl.cookie.BestMatchSpec.formatCookies
Java
7
star
14

dynq

Dynq is a DynamoDB client intended to make querying and sourcing environment variables from the commandline very easy.
Python
6
star
15

jfpm

Run fpm (which lets you build RPM's, DEB's, etc.) from a single standalone binary using the JVM.
Shell
6
star
16

grepby

Output counts of matching regular expressions like a group by for grep.
Go
5
star
17

gradle-wrapper-here

Drop a Gradle wrapper in the current directory.
Shell
4
star
18

moar-concurrent

This module contains a collection of useful builders and concurrency classes to assist in modeling complex or overly tweakable concurrent processing pipelines.
Java
4
star
19

oggtrackutil

This is a simple audio extraction utility written during a weekend to extract well-formed, single track WAV files from any compressed Ogg Vorbis audio file including those with more than 8 tracks.
C
3
star
20

ns4600

This is a small Python module to control the Promise SmartStor NS4600 NAS server.
Python
2
star
21

jfss

Run fss, which lets you provision cloud infrastructure Chef-style with only shell scripts, from a single standalone binary using the JVM.
Java
1
star
22

laptop-sleep-tool

Tinker with sleep mode settings on your laptop with this little tool.
Shell
1
star
23

python-debian-packaging

This is a collection of slides, etc. for my Python and Debian packaging talk.
JavaScript
1
star
24

windowtools

This is a collection of scripts for manipulating windows on various Linux desktop environments.
Shell
1
star
25

rholder.github.com

JavaScript
1
star
26

cram-maven-plugin

1
star
27

transaction-binding

This project extracts some of the transactional binding functionality from Alfresco 3.2's core libraries, and it aims to rely on very minimal external runtime dependencies.
Java
1
star
28

uci-security

UCI Security is a derivative of RBAC that slightly rearranges the components found in a traditional access control system. It includes the familiar idea of roles to the extent that they are used to control the access a particular user has within the system, but also introduces a new way of thinking about how their relationship to a particular situation is relevant.
1
star