-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle_
187 lines (165 loc) · 5.58 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/3.4.1/userguide/tutorial_java_projects.html
*/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.jfrog.bintray'
repositories {
jcenter()
}
sourceSets {
main {
java {
srcDirs 'src'
exclude 'src/test'
}
resources {
srcDirs 'impl'
include '*.pro'
}
}
test {
java.srcDirs 'src/test'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
task sourcesJar(type: Jar) {
from sourceSets.main.java.srcDirs + sourceSets.main.resources.srcDirs
classifier = 'sources'
}
// 解决中文乱码问题,在~/.gradle/wrapper/dists/gradle-x.x-all/xxx/gradle-x.x/bin/gradle(.bat)中找到以下参数并设置值:
// DEFAULT_JVM_OPTS="-Dfile.encoding=UTF-8"
// 但以上方法不行,下面方法才最终解决:
javadoc {
options {
encoding 'UTF-8'
charSet 'UTF-8'
}
}
// 系统已经有该任务
//task javadoc(type: Javadoc) {
// source = sourceSets.main.java.srcDirs
// // 没有android
//// classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
//}
// 由于会报错而中断"错误: 不允许使用自关闭元素",但文档已经正确输出了。
// ---->>>>后来发现把自关闭元素的"/"去掉即可:<br/>改为<br>. <<<<----
// 所以这样如果检查到文档正确输出了,则不再执行该任务。
// 效果上,第一次build会失败,但再来一次便会成功。
javadoc.onlyIf {
boolean empty = true
buildDir.eachDirMatch('docs') { d ->
d.eachDirMatch('javadoc') { j ->
println '->javadoc已经存在,不再执行该任务,以免异常中断。'
println '->path:' + j
empty = false
return
}
}
empty
}
// 要求不能使用自关闭元素如<br/>,所以暂不输出文档。
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
classifier = 'javadoc'
}
artifacts {
archives javadocJar
archives sourcesJar
}
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// 以下用于打包上传 /////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// 参见文档https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
group = "hobby.wei.c.anno"
version = "1.0.0"
def projectName = rootProject.name
def artifact = projectName.toLowerCase() // 不是project的属性,自定义变量,所以有def.
// 在命令gradle xxx后面带参数即可 -DforGithub=true/false 即可.
def forGithub = System.getProperty('forGithub') ?: true
def baseUrl = forGithub ? 'https://github.com/weichou' : 'https://git.oschina.net/wei.chou'
def siteUrl = baseUrl + '/Annoguard' // 项目的主页
def gitUrl = baseUrl + '/Annoguard.git' // Git仓库的url
// 安装到.m2本地仓库
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom.project {
// packaging 'aar' // 只有android有aar
name projectName
description 'A cool implementation for config Proguard use @Annotation instead of Script.' // 项目描述
url siteUrl
groupId project.group
artifactId artifact
version project.version
licenses {
// inceptionYear '2016' // 这一句会报错
license {
name 'The Apache Software License, Version 2.0'
url 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
// id 'weichou'
name 'Wei.Chou'
email 'weichou2010@gmail.com'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
//Properties properties = new Properties()
//properties.load(project.rootProject.file('gradle.properties').newDataInputStream())
bintray {
user = BINTRAY_USER // properties.getProperty("bintray.user")
key = BINTRAY_APIKEY // properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = 'maven'
name = artifact // 发布到JCenter上的项目名字
userOrg = BINTRAY_ORG
version {
name = project.version
}
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ['Apache-2.0']
publish = true
}
}
// 以下可用于发布到Maven仓库
//uploadArchives {
// repositories.mavenDeployer {
// repository(url: uri('repo'))
// repository(url: "http://host:port/xxx/repositories/snapshots/") {
// authentication(userName: "admin", password: "pwd")
// pom.groupId = "$project.group"
// pom.artifactId = "$artifact"
// pom.version = "$project.version"
// }
// }
//}
// 该命令用于生成jar包
//gradlew install -DforGithub=true/false
// 该命令用于上传
//gradlew bintrayUpload