-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio.sf.carte.java-conventions.gradle
169 lines (153 loc) · 4.33 KB
/
io.sf.carte.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
plugins {
id 'java-library'
id 'maven-publish'
id 'org.gradlex.extra-java-module-info'
}
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 "io.sf.graphics"
includeGroup "io.sf.w3"
}
}
}
group = 'io.sf.carte'
version = '0.1.0-SNAPSHOT'
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
excludes += ["**/*.java"]
}
}
test {
java {
srcDirs = ['junit']
}
resources {
srcDirs = ['junit']
excludes += ["**/*.java"]
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_11
withJavadocJar()
withSourcesJar()
registerFeature('jfreechart') {
usingSourceSet(sourceSets.main)
}
registerFeature('xchart') {
usingSourceSet(sourceSets.main)
}
}
dependencies {
implementation "io.sf.carte:xml-dtd:${xmlDtdVersion}"
api "io.sf.carte:css4j:${css4jVersion}"
implementation "nu.validator:htmlparser:${htmlparserVersion}"
}
extraJavaModuleInfo {
automaticModule("htmlparser-${htmlparserVersion}.jar", 'htmlparser')
automaticModule('com.madgag:animated-gif-lib', 'com.madgag.gif.fmsware')
automaticModule('commons-logging:commons-logging', 'commons.logging')
automaticModule("org.apache.xmlgraphics:xmlgraphics-commons", 'xmlgraphics.commons')
automaticModule('de.erichseifert.vectorgraphics2d:VectorGraphics2D', 'vectorgraphics2d')
}
tasks.register('jvmVersionAttribute') {
description = "Set the correct 'org.gradle.jvm.version' attribute"
dependsOn compileJava
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 Java 8 bytecode'
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() {
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.dependsOn jvmVersionAttribute
classes.finalizedBy checkLegacyJava
jar.dependsOn checkLegacyJava
publishing {
publications {
maven(MavenPublication) {
from(components.java)
suppressAllPomMetadataWarnings()
}
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Javadoc) {
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.txt to Windows line endings'
from "$rootDir/LICENSE.txt"
}
tasks.withType(AbstractArchiveTask).configureEach {
// Reproducible build
preserveFileTimestamps = false
reproducibleFileOrder = true
// Copy license file
dependsOn lineEndingConvCopy
from ("$buildDir/tmp/crlf/LICENSE.txt") {
into 'META-INF'
}
}