-
Notifications
You must be signed in to change notification settings - Fork 2
/
echosvg.java-conventions.gradle
267 lines (241 loc) · 7.21 KB
/
echosvg.java-conventions.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
plugins {
id 'java-library'
id 'maven-publish'
id 'org.owasp.dependencycheck'
id 'checkstyle'
id 'jacoco'
id 'com.github.jk1.dependency-license-report'
}
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.graphics'
includeGroup 'io.sf.w3'
includeGroup 'io.sf.jclf'
}
}
}
group = 'io.sf.carte'
version = '2.0-SNAPSHOT'
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.register('jvmVersionAttribute') {
description = "Set the correct 'org.gradle.jvm.version' attribute"
def jvmVersionAttribute = Attribute.of('org.gradle.jvm.version', Integer)
configurations.each {
if (it.canBeConsumed) {
def categoryAttr = it.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)
if (categoryAttr != null && categoryAttr.name == Category.LIBRARY) {
def usageAttr = it.attributes.getAttribute(Usage.USAGE_ATTRIBUTE)
if (usageAttr != null && (usageAttr.name == Usage.JAVA_API
|| usageAttr.name == Usage.JAVA_RUNTIME)) {
it.attributes.attribute(jvmVersionAttribute, 8)
}
}
}
}
}
tasks.register('compileLegacyJava', JavaCompile) {
description = 'Compile to Java 8 bytecode, except module-info'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
source = sourceSets.main.java
dependsOn configurations.compileClasspath
classpath = sourceSets.main.compileClasspath
destinationDirectory = sourceSets.main.java.destinationDirectory
modularity.inferModulePath = false
excludes = ['module-info.java']
}
compileJava {
includes = ['module-info.java']
dependsOn compileLegacyJava
classpath = sourceSets.main.compileClasspath
}
// Check bytecode version, in case some other task screws it
tasks.register('checkLegacyJava') {
description = 'Check that classes are Java 8 bytecode (except module-info)'
enabled = enabled && !project.getPluginManager().hasPlugin('eclipse')
def classdir = sourceSets.main.output.classesDirs.files.stream().findAny().get()
def classfiles = fileTree(classdir).matching({it.exclude('module-info.class')}).files
doFirst() {
classfiles.each {
classfile ->
def classbytes = classfile.bytes
def bcversion = classbytes[6] * 128 + classbytes[7]
if (bcversion != 52) {
throw new GradleException("Bytecode on " + classfile.name +
" is not valid Java 8. Version should be 52, instead is " + bcversion)
}
}
}
}
classes.dependsOn jvmVersionAttribute, checkLicense
classes.finalizedBy checkLegacyJava
jar.dependsOn checkLegacyJava
//create a project Jar with all dependencies
tasks.register("${project.name}-jar-with-deps", Jar) {
description = "Create a ${project.name} fat jar with all dependencies."
group = 'Fat jar'
archiveClassifier = 'with-deps'
dependsOn configurations.compileClasspath
dependsOn configurations.runtimeClasspath
doFirst {
from sourceSets.main.output
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
from {
configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
}
}
with jar
duplicatesStrategy = 'exclude'
// Exclusions
// ----------
exclude 'overview.html'
// Provided by Java SE
exclude 'javax/**'
// Not used by EchoSVG
exclude 'org/w3c/css/sac/**'
// The next ones are provided by java.xml module
exclude 'org/w3c/dom/*'
exclude 'org/w3c/dom/bootstrap/**'
exclude 'org/w3c/dom/events/**'
exclude 'org/w3c/dom/ls/**'
exclude 'org/w3c/dom/ranges/**'
exclude 'org/w3c/dom/traversal/**'
exclude 'org/w3c/dom/views/**'
exclude 'org/xml/**'
// Provided by jdk.xml.dom module
exclude 'org/w3c/dom/css/**'
exclude 'org/w3c/dom/html/**'
exclude 'org/w3c/dom/stylesheets/**'
exclude 'org/w3c/dom/xpath/**'
// Modularity does not apply here
exclude 'module-info.class'
}
// Copy jar files to 'jar' directory
tasks.register('copyJars', Copy) {
description = 'Copy jar files to \'jar\' directory'
dependsOn jar,sourcesJar
dependsOn ':echosvg-all:jar'
include '**/*.jar'
excludes = ['IWasLoaded*.jar', 'JarCheckPermissions*.jar',
'JarPolicyTest.jar', 'echosvg-*-jmh.jar']
from layout.buildDirectory.dir("libs")
into "${rootDir}/jar"
}
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.links 'https://docs.oracle.com/en/java/javase/11/docs/api/'
}
tasks.register('lineEndingConvCopy', CRLFConvertCopy) {
description 'Convert LICENSE and NOTICE to Windows line endings'
from "$rootDir/LICENSE"
from "$rootDir/NOTICE"
}
// Reproducible build
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
// Copy license file
dependsOn lineEndingConvCopy
from ("$buildDir/tmp/crlf/LICENSE") {
into 'META-INF'
}
from ("$buildDir/tmp/crlf/NOTICE") {
into 'META-INF'
}
}
// jacoco
jacocoTestReport {
dependsOn test
}
// Check licenses
licenseReport {
allowedLicensesFile = new File("$rootDir/buildSrc/allowed-licenses.json")
}
checkstyle {
toolVersion = "${checkstyleVersion}"
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
pom {
url = "https://github.com/css4j/echosvg/wiki"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = "scm:git:https://github.com/css4j/echosvg.git"
developerConnection = "scm:git:git://[email protected]:css4j/echosvg.git"
url = "https://github.com/css4j/echosvg"
}
}
}
}
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
}
}
}
}
tasks.withType(PublishToMavenRepository) { task ->
dependsOn checkLegacyJava
doFirst {
if (repository == publishing.repositories.getByName('mavenRepo')) {
logger.lifecycle "Deploying artifacts to \"${it.repository.url}\""
}
}
}