Created
July 10, 2015 06:03
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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