-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
158 lines (133 loc) · 3.89 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: file('common.gradle')
buildscript {
repositories {
maven {url "https://maven.aliyun.com/repository/google/"}
maven {url "https://maven.aliyun.com/repository/public/"}
mavenCentral()
// maven {
// url 'file:///D:/maven_local'
// }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// classpath 'com.example.plugintest:plugintest:1.0.7'
// classpath 'com.yuhb.upload:upload:1.0.1'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
//统一配置所有子project的集合
allprojects {
repositories {
maven {url "https://maven.aliyun.com/repository/google/"}
maven {url "https://maven.aliyun.com/repository/public/"}
mavenCentral()
maven {
url 'file:///D:/maven_local'
}
}
group 'cpm_group'
version 1.0
}
//包括子Project
subprojects {Project project ->
if(plugins.hasPlugin('com.android.library')){
apply from:'../publishMaven.gradle'
}
}
this.beforeEvaluate {
// println getUtf_8Str('配置阶段开始前...')
}
this.afterEvaluate {
// println getUtf_8Str('配置阶段结束后...')
}
this.gradle.buildFinished {
// println getUtf_8Str('任务执行阶段完成...')
}
//文件:路径api
//println "this root file path:"+getRootDir().absolutePath
//println "this buildDir path:"+getBuildDir().absolutePath
//println "this ProjectDir path:"+getProjectDir().absolutePath
//文件:file api
println getFileContent('common.gradle')
def getFileContent(String path){
try {
File file = file(path)
return file.text
}catch(GradleException e){
println 'file is not found'
}
return null
}
//文件拷贝
copy {
from file('gradlew')
into getRootProject().getBuildDir().absolutePath
exclude {}
rename {}
}
//其他api
buildscript { ScriptHandler handler ->
//配置工程仓库地址
handler.repositories { RepositoryHandler repositoryHandler ->
repositoryHandler.google()
repositoryHandler.mavenCentral()
// repositoryHandler.maven { MavenArtifactRepository mavenArtifactRepository ->
// mavenArtifactRepository.url '私服地址'
// mavenArtifactRepository.name '仓库名称'
// mavenArtifactRepository.credentials {PasswordCredentials passwordCredentials ->
// username 'yuhb'
// password 'admin123'
// }
// }
}
//配置工程插件依赖地址
handler.dependencies { DependencyHandler dependencyHandler ->
classpath "com.android.tools.build:gradle:4.1.1"
// gradleApi()
}
}
//获取所有的Project
this.getAllprojects()
//获取子Project
this.getSubprojects()
//获取父Project
this.getParent()
//获取rootProject
this.getRootProject()
//通过project名称获取project可以在这里配置
project('app') { Project project ->
// println project.name
// println project.group
apply plugin: 'com.android.application'
// group 'com.immoc'
// version '1.0'
dependencies {
}
android {
}
}
getProjects()
def getProjects(){
// println '----------------'
// println '--------root project--------'
// println '----------------'
this.getAllprojects().eachWithIndex{ Project entry, int i ->
// if(i == 0){
// println "rootProject is $entry.name"
// }else{
// println "subProject $entry.name"
// }
}
}
def getGbkStr(String str){
return new String(str.getBytes(),'gbk')
}
def getUtf_8Str(String str){
return new String(str.getBytes(),'utf-8')
}