-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
194 lines (177 loc) · 5.37 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
plugins {
id 'java-library'
id 'maven-publish'
id 'checkstyle'
}
group = 'io.sf.graphics'
version = '1.0'
description = 'io.sf.graphics:legacy-colors'
repositories {
maven {
url = uri('https://repo.maven.apache.org/maven2/')
}
maven {
url "https://css4j.github.io/maven/"
mavenContent {
releasesOnly()
}
content {
includeGroup "io.sf.graphics"
}
}
}
dependencies {
testImplementation 'commons-io:commons-io:2.16.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
checkstyle {
toolVersion = '10.17.0'
}
test {
useJUnitPlatform()
}
java {
withJavadocJar()
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
classes.finalizedBy checkLegacyJava
jar.dependsOn checkLegacyJava
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'
}
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
pom {
description = "Legacy color graphics (derived from xmlgraphics-commons)"
url = "https://github.com/css4j/legacy-colors"
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/legacy-colors.git"
developerConnection = "scm:git:git://git@github.com:css4j/legacy-colors.git"
url = "https://github.com/css4j/legacy-colors"
}
}
}
}
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
}
}
}
}