-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
292 lines (265 loc) · 7.13 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
plugins {
id 'java-library'
id 'maven-publish'
id 'org.gradlex.extra-java-module-info' version '1.9'
}
group = 'io.sf.carte'
version = '5.1-SNAPSHOT'
description = 'css4j-dom4j'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
registerFeature('xmlpull') {
usingSourceSet(sourceSets.main)
}
registerFeature('useragent') {
usingSourceSet(sourceSets.main)
}
}
dependencies {
api('io.sf.carte:css4j') {
version {
strictly '[4.2.2,)'
prefer '5.0'
}
}
useragentImplementation('io.sf.carte:css4j-agent') {
version {
strictly '[3.4.0,)'
prefer '5.0'
}
}
/*
* Any dom4j version can be used, but tests may not pass with versions prior
* to 2.1.1, due to changes in dom4j's defaults.
*/
api('org.dom4j:dom4j') {
version {
require '[1.6.0,)'
prefer '2.1.4'
}
}
xmlpullImplementation 'xmlpull:xmlpull:1.2.0'
xmlpullImplementation 'xpp3:xpp3_min:1.2.0'
testImplementation group: 'io.sf.carte', name: 'css4j', classifier: 'tests',
version: '5.0'
testImplementation 'jaxen:jaxen:1.2.0'
testImplementation 'org.slf4j:slf4j-api:2.0.13'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.3'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// css4j 4.x tests still use JUnit 4
testImplementation 'org.junit.vintage:junit-vintage-engine:5.11.3'
}
extraJavaModuleInfo {
failOnMissingModuleInfo.set(false)
automaticModule('htmlparser-1.4.16.jar', 'htmlparser')
}
repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
maven {
url "https://css4j.github.io/maven/"
mavenContent {
releasesOnly()
}
content {
includeGroup 'io.sf.carte'
includeGroup 'io.sf.jclf'
includeGroup 'xmlpull'
includeGroup 'xpp3'
}
}
}
sourceSets {
main {
java {
srcDirs = ['src']
includes += ["**/*.java"]
}
resources {
srcDirs = ['src']
excludes += ["**/*.java"]
}
}
test {
java {
srcDirs = ['junit']
includes += ["**/*.java"]
}
resources {
srcDirs = ['junit']
excludes += ["**/*.java"]
}
}
}
test {
useJUnitPlatform()
}
tasks.register('testsJar', Jar) {
archiveClassifier = 'tests'
from(sourceSets.test.output)
}
configurations {
tests
}
artifacts {
tests testsJar
}
tasks.compileJava {
excludes += ['module-info.java']
modularity.inferModulePath = false
}
tasks.register('compileModuleInfo', JavaCompile) {
description = 'Compile module-info to Java 11 bytecode'
dependsOn tasks.compileJava
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
source = sourceSets.main.java
classpath = sourceSets.main.compileClasspath
destinationDirectory = sourceSets.main.java.destinationDirectory
modularity.inferModulePath = true
includes = ['module-info.java']
}
classes.dependsOn compileModuleInfo
// Check bytecode version, in case some other task screws it
tasks.register('checkLegacyJava') {
description = 'Check that classes are Java 8 bytecode (except module-info)'
def classdir = sourceSets.main.output.classesDirs.files.stream().findAny().get()
def classfiles = fileTree(classdir).matching({it.exclude('module-info.class')}).files
doFirst() {
if (!classfiles.isEmpty()) {
def classfile = classfiles.stream().findAny().get()
if (classfile != null) {
def classbytes = classfile.bytes
def bcversion = classbytes[6] * 128 + classbytes[7]
if (bcversion != 52) {
throw new GradleException("Bytecode on " + classfile +
" is not valid Java 8. Version should be 52, instead is " + bcversion)
}
}
}
}
}
classes.finalizedBy checkLegacyJava
// Copy jar files to 'jar' directory
tasks.register('copyJars', Copy) {
description = 'Copy jar files to \'jar\' directory'
dependsOn tasks.build
dependsOn 'testsJar'
include '**/*.jar'
excludes = ['slf4j*.jar']
from layout.buildDirectory.dir("libs")
from configurations.runtimeClasspath
into "${rootDir}/jar"
}
tasks.register('lineEndingConversion', CRLFConvert) {
description 'Convert top-level files to Windows line endings'
file "$rootDir/RELEASE_NOTES.md"
}
tasks.register('lineEndingConvCopy', CRLFConvertCopy) {
description 'Convert LICENSE.txt to Windows line endings'
from "$rootDir/LICENSE.txt"
}
tasks.register('cleanBuildSrc') {
description = 'Clean the buildSrc directory'
doLast {
delete("$rootDir/buildSrc/build")
}
}
tasks.named('clean') {
finalizedBy('cleanBuildSrc')
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charset', 'UTF-8')
options.overview = 'src/overview.html'
options.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
options.links 'https://css4j.github.io/api/latest/'
options.links 'https://dom4j.github.io/javadoc/2.1.1/'
}
tasks.withType(AbstractArchiveTask).configureEach {
// Reproducible build
preserveFileTimestamps = false
reproducibleFileOrder = true
// Copy license file
dependsOn lineEndingConvCopy
from ("$buildDir/tmp/crlf/LICENSE.txt") {
into 'META-INF'
}
}
build.dependsOn lineEndingConversion
tasks.withType(PublishToMavenRepository) { task ->
doFirst {
if (repository == publishing.repositories.getByName('mavenRepo')) {
logger.lifecycle "Deploying artifacts to \"${it.repository.url}\""
}
}
}
publishing {
publications {
maven(MavenPublication) {
description = 'css4j DOM4J module'
from(components.java)
suppressAllPomMetadataWarnings()
artifact(testsJar)
pom {
description = 'css4j DOM4J module'
url = "https://css4j.github.io/"
licenses {
license {
name = "BSD 3-clause license"
url = "https://css4j.github.io/LICENSE.txt"
}
}
scm {
connection = "scm:git:https://github.com/css4j/css4j-dom4j.git"
developerConnection = "scm:git:git://[email protected]:css4j/css4j-dom4j.git"
url = "https://github.com/css4j/css4j-dom4j"
}
}
}
}
repositories {
maven {
name = 'mavenRepo'
/*
* The following section applies to the 'publish' task:
*
* If you plan to deploy to a repository, please configure the
* 'mavenReleaseRepoUrl' and/or 'mavenSnapshotRepoUrl' properties
* (for example in GRADLE_USER_HOME/gradle.properties).
*
* Otherwise, Gradle shall create a 'build/repository' subdirectory
* at ${rootDir} and deploy there.
*
* Properties 'mavenRepoUsername' and 'mavenRepoPassword' can also
* be set (generally from command line).
*/
def releasesUrl
def snapshotsUrl
if (project.hasProperty('mavenReleaseRepoUrl') && project.mavenReleaseRepoUrl) {
releasesUrl = mavenReleaseRepoUrl
} else {
releasesUrl = "${buildDir}/repository/releases"
}
if (project.hasProperty('mavenSnapshotRepoUrl') && project.mavenSnapshotRepoUrl) {
snapshotsUrl = mavenSnapshotRepoUrl
} else {
snapshotsUrl = "${buildDir}/repository/snapshots"
}
url = version.endsWith('-SNAPSHOT') ? snapshotsUrl : releasesUrl
if (project.hasProperty('mavenRepoUsername') &&
project.hasProperty('mavenRepoPassword')) {
credentials.username = mavenRepoUsername
credentials.password = mavenRepoPassword
}
}
}
}