1
+ import org.gradle.api.internal.artifacts.DefaultProjectComponentIdentifier
1
2
import org.xml.sax.InputSource
2
3
import org.xml.sax.SAXException
3
4
import org.xml.sax.helpers.DefaultHandler
@@ -22,13 +23,23 @@ configurations {
22
23
class FaiyExt {
23
24
private boolean requireHostVersion = true ;
24
25
26
+ private String hostDependenciesToExclude;
27
+
25
28
public boolean getRequireHostVersion () {
26
29
return requireHostVersion
27
30
}
28
31
29
32
public void setRequireHostVersion (boolean required ) {
30
33
this . requireHostVersion = required
31
34
}
35
+
36
+ public String getHostDependenciesToExclude () {
37
+ return this . hostDependenciesToExclude;
38
+ }
39
+
40
+ public void setHostDependenciesToExclude (String hostDependenciesToExclude ) {
41
+ this . hostDependenciesToExclude = hostDependenciesToExclude;
42
+ }
32
43
}
33
44
extensions. create(' fairy' , FaiyExt )
34
45
@@ -42,24 +53,39 @@ def hostBarRootDir = rootProject.rootDir.absolutePath + '/.gradle/fairy/baseline
42
53
def defaultExtraDir = hostBarRootDir + " unspecified"
43
54
def hostDependencies = defaultExtraDir + " /" + hostDependencyFile
44
55
def currentSelectedBar = defaultExtraDir + " /" + hostBar
56
+ def boolean startParameterWithhDebugOrRelease = false ;
45
57
gradle. startParameter. taskNames. each { startTaskName ->
46
58
if (startTaskName. contains(" Debug" )) {
47
59
hostDependencies = hostBarRootDir + " debug" + " /" + hostDependencyFile
48
60
currentSelectedBar = hostBarRootDir + " debug" + " /" + hostBar
61
+ startParameterWithhDebugOrRelease = true ;
49
62
} else if (startTaskName. contains(" Release" )) {
50
63
hostDependencies = hostBarRootDir + " release" + " /" + hostDependencyFile
51
64
currentSelectedBar = hostBarRootDir + " release" + " /" + hostBar
65
+ startParameterWithhDebugOrRelease = true ;
52
66
}
53
67
}
54
68
55
69
println " 执行命令决定了bar文件依赖路径!"
56
70
println " >>>" + hostBarRootDir
57
71
println " >>>" + currentSelectedBar
58
- println " >>>" + hostDependencies
59
72
60
- if (file(hostDependencies). exists()) {
61
- println " >>>apply from: " + hostDependencies
62
- apply from : hostDependencies
73
+ if (fairy. hostDependenciesToExclude != null && file(fairy. hostDependenciesToExclude). exists()) {
74
+ println " >>>apply from: " + fairy. hostDependenciesToExclude
75
+ apply from : fairy. hostDependenciesToExclude
76
+ } else {
77
+ if (file(hostDependencies). exists()) {
78
+ println " >>>apply from: " + hostDependencies
79
+ apply from : hostDependencies
80
+ } else {
81
+ if (startParameterWithhDebugOrRelease) {
82
+ throw new Exception (" 由于gradle脚本的执行顺序问题,宿主基线包可能还没编译、${ hostDependencies} 文件可能还没有从插件依赖的基线包中解压出来\n " +
83
+ " 此时需要自行手动下载hostBar并从中解压出host_dependencies.gradle, 再将此文件路径配置到插件工程的build.gradle内:\n " +
84
+ " fairy {\n " +
85
+ " hostDependenciesToExclude = \" <path/to/host_dependencies.gradle>\"\n " +
86
+ " }\n " )
87
+ }
88
+ }
63
89
}
64
90
65
91
android. androidResources. additionalParameters(
@@ -179,6 +205,7 @@ afterEvaluate {
179
205
it. doLast {
180
206
if (rtConfig. isCanBeResolved() && rtConfig. getResolutionAlternatives() == null ) {
181
207
TreeSet hashSet = new TreeSet ()
208
+ // rtConfig.getIncoming().beforeResolve(new Action<ResolvableDependencies>() {})
182
209
rtConfig. getIncoming(). getResolutionResult(). getRoot(). getDependencies(). each() { dependencyResult ->
183
210
if (dependencyResult instanceof ResolvedDependencyResult ) {
184
211
add(hashSet, dependencyResult)
@@ -190,13 +217,11 @@ afterEvaluate {
190
217
dependenciesTxt. append(" // variant is ${ varName} \n " )
191
218
String hostTxt = new File (hostDependencies). text
192
219
hashSet. each { moduleFullName ->
193
- if (! moduleFullName. startsWith(" project " )) {// 源码依赖的不处理
194
- if (hostTxt. contains(moduleFullName)) {
195
- dependenciesTxt. append(" // NOTICE: This module is both in host and plugin apk file!\n " )
196
- }
197
- dependenciesTxt. append(moduleFullName)
198
- dependenciesTxt. append(" \n " )
220
+ if (hostTxt. contains(moduleFullName)) {
221
+ dependenciesTxt. append(" // NOTICE: This module is both in host and plugin apk file!\n " )
199
222
}
223
+ dependenciesTxt. append(moduleFullName)
224
+ dependenciesTxt. append(" \n " )
200
225
}
201
226
dependenciesTxt. append(" \n " )
202
227
}
@@ -296,7 +321,9 @@ afterEvaluate {
296
321
}
297
322
298
323
def add (Set set , ResolvedDependencyResult dependencyResult ) {
299
- set. add(dependencyResult. getSelected(). getId(). displayName)
324
+ if (! (dependencyResult. getSelected(). getId() instanceof DefaultProjectComponentIdentifier )) {// 源码依赖的不处理
325
+ set. add(dependencyResult. getSelected(). getId(). displayName)
326
+ }
300
327
dependencyResult. getSelected(). getDependencies(). each() { childDependencyResult ->
301
328
if (childDependencyResult instanceof ResolvedDependencyResult ) {
302
329
add(set, childDependencyResult)
0 commit comments