Created
April 13, 2012 07:20
-
-
Save musketyr/2374771 to your computer and use it in GitHub Desktop.
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
def stageDir = buildDir.path + '/tmp/fatjar-stage/' | |
task fatjarStageClasses(type: Copy, dependsOn: classes){ | |
from sourceSets.main.output.classesDir | |
into stageDir | |
} | |
task fatjarStageResources(type: Copy, dependsOn: classes){ | |
from sourceSets.main.output.resourcesDir | |
into stageDir | |
} | |
task fatjarStageDependencies(type: Copy){ | |
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } | |
into stageDir | |
} | |
private boolean isServiceFile(File file){ | |
file.parent?.endsWith('META-INF/services') || file.parent?.endsWith('META-INF/services/') | |
} | |
private FileCollection collectFatJarFiles(){ | |
def fileCollections = fileTree sourceSets.main.output.classesDir | |
fileCollections += fileTree sourceSets.main.output.resourcesDir | |
configurations.compile.each { | |
fileCollections = fileCollections + (it.isDirectory() ? it : zipTree(it)) | |
} | |
fileCollections | |
} | |
task fatjarCollectServices(dependsOn: [fatjarStageClasses, fatjarStageResources, fatjarStageDependencies]) << { | |
def serviceFiles = collectFatJarFiles().filter{ isServiceFile(it) } | |
File serviceDir = new File(stageDir + 'META-INF/services/') | |
serviceDir.deleteDir() | |
serviceDir.mkdirs() | |
for(File file in serviceFiles.files){ | |
def serviceFile = new File(serviceDir, file.name) | |
if(!serviceFile.exists()){ | |
serviceFile.createNewFile() | |
} | |
serviceFile.append file.text.trim() + '\n' | |
} | |
} | |
task fatJar(type: Jar, dependsOn: fatjarCollectServices) { | |
from stageDir | |
} | |
task slimWar(type: War, dependsOn: fatJar) { | |
classpath = files fatJar.archivePath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment