在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):rholder/gradle-one-jar开源软件地址(OpenSource Url):https://github.com/rholder/gradle-one-jar开源编程语言(OpenSource Language):Groovy 63.3%开源软件介绍(OpenSource Introduction):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:
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 artifacts {
archives awesomeFunJar
} If you don't like the name of the final artifact, you can change it just like
any other Gradle task awesomeFunJar(type: OneJar) {
mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
archiveName = 'koala.jar'
} ##Advanced Features
The current incarnation of the ###Selectable One-JAR version
By default, the 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 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 // 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 task awesomeFunJar(type: OneJar) {
mainClass = 'com.github.rholder.awesome.MyAwesomeMain'
manifest {
attributes 'Timestamp': String.valueOf(System.currentTimeMillis())
attributes 'ContainsXML': 'No'
}
} ###Merge base 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
###Add native libraries
Files added to the 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 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 ##Building from source
The check out sources
compile and test, build all jars
install all jars into your local Maven cache
##License
The ##Contributors
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论