-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathbuild.gradle
70 lines (59 loc) · 1.67 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
60
61
62
63
64
65
66
67
68
69
70
plugins {
id 'application'
}
application {
mainClassName = 'com.yworks.example.HelloWorld'
}
jar {
manifest {
attributes(
'Main-Class': application.mainClassName
)
}
}
repositories {
mavenCentral()
}
configurations {
yguard
}
dependencies {
yguard 'com.yworks:yguard:4.1.1'
}
task obfuscate {
dependsOn jar
group 'yGuard'
description 'Obfuscates the java archive.'
doLast {
def archivePath = jar.archiveFile.get().asFile.path
def unobfJar = archivePath.replace(".jar", "_unobf.jar")
ant.move(file: archivePath, tofile: unobfJar, verbose: true)
ant.taskdef(
name: 'yguard',
classname: 'com.yworks.yguard.YGuardTask',
classpath: configurations.yguard.asPath
)
ant.yguard {
inoutpair(in: unobfJar, out: archivePath)
rename(logfile: "${buildDir}/${rootProject.name}_renamelog.xml") {
adjust(replacePath: false) {
// keep the complete path to the resources even if
// package com.yworks.example gets obfuscated by name
include(name: "com/yworks/example/resources/*")
}
adjust(replaceContent: true, replaceContentSeparator: ".", replaceName: true) {
// plain-text class names in the config files will
// be replaced with the obfuscated name versions
// replace the .properties files' names with the obfuscated
// versions if the corresponding .class files get obfuscated
include(name: "**/*.properties")
}
keep {
method(name: "void main(java.lang.String[])", "class": application.mainClassName)
}
}
}
}
}
distTar.dependsOn obfuscate
distZip.dependsOn obfuscate