-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
59 lines (47 loc) · 1.41 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
apply plugin: 'java'
group = 'com.acme'
version = '1.0'
dependencies {
compile 'acme:a:1.0'
compile 'acme:b:1.0'
}
repositories {
mavenRepo urls: "file:///${toJavaPath(projectDir.absolutePath)}/lib"
}
private def toJavaPath(path) {
return path.replace(File.separator, '/')
}
task jarWithDeps(type: Jar, dependsOn: classes) {
archiveName = "${baseName}-by-gradle.${extension}"
compileDeps = configurations.compile.collect { zipTree(it) }
// this project's classes and all deps
from sourceSets*.classesDir
from compileDeps
manifest {
attributes 'Main-Class': 'ReadSpi'
}
}
task jarWithDeps2(type: Jar, dependsOn: classes) {
mergeDir = "${buildDir}/merge"
// might need a lazy var in a multi-module project where deps are inherited
runtimeDeps = configurations.runtime.collect { zipTree(it) }
myServiceConfig = 'META-INF/services/MyService.config'
doFirst {
new File(mergeDir).delete()
mergeFiles(mergeDir, runtimeDeps, myServiceConfig)
}
// this project's classes and all deps
from sourceSets*.classesDir
from(runtimeDeps) {
exclude myServiceConfig
}
from mergeDir
}
private def mergeFiles(targetDir, fileTrees, relativePath) {
// prepare the merge
mergedFile = new File("${targetDir}/${relativePath}")
new File(mergedFile.parent).mkdirs()
fileTrees*.matching({ include "**/${relativePath}" })*.each {
mergedFile << it.bytes
}
}