Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Created July 10, 2015 06:03
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukhnos/31abbea7492d06179ecb to your computer and use it in GitHub Desktop.
Save lukhnos/31abbea7492d06179ecb to your computer and use it in GitHub Desktop.
A typical Java project gradle setup that combines META-INF/services in the "super JAR"
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
// ...
}
jar {
// From http://cmoz.me/blog/2014/11/service-files-uber-jars-and-gradle/
doFirst {
def serviceDir = file("$buildDir/META-INF/services")
serviceDir.deleteDir()
serviceDir.mkdirs()
// copy all service files from deps to buildDir
for(file in configurations.runtime) {
zipTree(file).matching{ include 'META-INF/services/*' }.each { f ->
new File(serviceDir, f.name) << f.getText("UTF-8")
}
}
}
manifest {
attributes "Main-Class": "com.example.Main"
}
from(configurations.runtime.collect{ it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/**' // Don't let Gradle merge service files
}
// Include service files from the buildDir.
from fileTree(buildDir).matching{ include 'META-INF/services/*' }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment