-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaspectj.gradle
67 lines (62 loc) · 2.6 KB
/
aspectj.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
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
google()
mavenCentral()
}
}
// app 和 lib 属性不同
def variants = null
if (project.android.hasProperty("applicationVariants")) {
variants = project.android.applicationVariants
} else if (project.android.hasProperty("libraryVariants")) {
variants = project.android.libraryVariants
}
variants.all { variant ->
variant.outputs.all { output ->
def fullName = ""
output.name.tokenize('-').eachWithIndex { token, index ->
fullName = fullName + (index == 0 ? token : token.capitalize())
}
JavaCompile javaCompile = variant.javaCompileProvider.get()
javaCompile.doLast {
String[] javaArgs = ["-showWeaveInfo",
"-1.8",
"-inpath", javaCompile.destinationDir.toString(),
"-aspectpath", javaCompile.classpath.asPath,
"-d", javaCompile.destinationDir.toString(),
"-classpath", javaCompile.classpath.asPath,
"-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)]
println "ajc javaArgs: " + Arrays.toString(javaArgs)
String[] kotlinArgs = ["-showWeaveInfo",
"-1.8",
"-inpath", project.buildDir.path + "/tmp/kotlin-classes/" + fullName,
"-aspectpath", javaCompile.classpath.asPath,
"-d", project.buildDir.path + "/tmp/kotlin-classes/" + fullName,
"-classpath", javaCompile.classpath.asPath,
"-bootclasspath", project.android.bootClasspath.join(
File.pathSeparator)]
println "ajc kotlinArgs: " + Arrays.toString(kotlinArgs)
def wv = configurations.create("weaving")
dependencies {
weaving 'org.aspectj:aspectjtools:1.9.8'
}
try {
javaexec {
classpath = wv
main = "org.aspectj.tools.ajc.Main"
args javaArgs
}
} catch (Exception ignored) {
}
try {
javaexec {
classpath = wv
main = "org.aspectj.tools.ajc.Main"
args kotlinArgs
}
} catch (Exception ignored) {
}
}
}
}