-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
executable file
·201 lines (164 loc) · 6.01 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
plugins {
id 'java'
id 'java-library'
id 'idea'
id 'maven-publish' // NB: previously used 'maven', that is deprecated
// See
// https://central.sonatype.org/publish/publish-gradle/
// https://medium.com/@nmauti/sign-and-publish-on-maven-central-a-project-with-the-new-maven-publish-gradle-plugin-22a72a4bfd4b
// https://github.com/jmini/html-publish-helper/blob/master/build.gradle
id 'signing' // See https://docs.gradle.org/current/userguide/signing_plugin.html
id 'application'
id 'org.jetbrains.dokka' version '1.9.20'
id 'org.jetbrains.kotlin.jvm' version '1.9.24'
}
group 'io.github.orienteering-oss'
archivesBaseName = "iofXml"
version '1.4.0-SNAPSHOT'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
repositories {
mavenCentral()
}
// Needed to download sources and javadoc for imported modules
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
def generated_dir = "src/main/java"
sourceSets {
generated {
java.srcDir "$generated_dir"
}
}
// JAXB configuration holds classpath for running the JAXB XJC compiler
configurations {
jaxb
}
dependencies {
jaxb "org.glassfish.jaxb:jaxb-xjc:4.0.5"
jaxb "org.glassfish.jaxb:jaxb-runtime:4.0.5" // See also https://github.com/bjornvester/xjc-gradle-plugin/issues/21#issuecomment-904518682
// Generated code depends on the JAXB API, which is removed from base Java in JDK 11
generatedImplementation "org.glassfish.jaxb:jaxb-runtime:4.0.5"
implementation "org.glassfish.jaxb:jaxb-runtime:4.0.5"
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.2' // In JAXB v3, 'javax.xml.bind' was moved to 'jakarta.xml.bind'
// The generated IOF v2/3 files
implementation sourceSets.generated.output
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-jsonSchema', version: '2.17.2'
testImplementation platform("org.junit:junit-bom:5.10.3")
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation 'org.jetbrains.kotlin:kotlin-test'
}
test {
useJUnitPlatform()
}
// Cookie cutter function for defining multiple XJC tasks
def addXjcTask(taskName, schema, pkg, dest) {
// If you haven't already, create the generated output dir before running XJC or it will fail
file(dest).mkdirs()
// The main XJC task, calls XJCFacade which is the entry point of the XJC JAR
tasks.create(name: taskName, type: JavaExec) {
classpath configurations.jaxb
mainClass = 'com.sun.tools.xjc.XJCFacade'
// To explore available args, download the XJC JAR and run java -jar jaxb-xjc.jar --help
args schema, "-p", pkg, "-d", dest, "-no-header" // no-header removes timestamp header in each file
}
// Add a dependency on the new task so it gets invoked (depends on compilation)
//compileGeneratedJava.dependsOn tasks.getByName(taskName) // using 'generateSources' instead for now
}
// Add all the XJC tasks you need
addXjcTask("iof_v2",
"src/main/resources/iof_v2.xsd",
"${archivesBaseName}.v2",
"$generated_dir")
addXjcTask("iof_v3",
"src/main/resources/iof_v3.xsd",
"${archivesBaseName}.v3",
"$generated_dir")
tasks.register('generateSources') {
description "Generate Java sources fram XSD files"
dependsOn tasks.getByName('iof_v2')
dependsOn tasks.getByName('iof_v3')
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
archives javadocJar
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.name
version project.version
artifacts = [javadocJar, sourcesJar]
from components.java
pom {
name = 'iofXml'
description = 'Java classes generated from IOF XSD v3 and v2'
url = 'https://github.com/orienteering-oss/iof-xml'
licenses {
license {
name = 'GNU General Public License v3.0'
url = 'https://github.com/orienteering-oss/iof-xml/blob/main/LICENSE'
}
}
developers {
developer {
id = 'mikaello'
name = 'mikaello'
email = 'eeeeeeeefeeeeeeeeee+ooosss@gmail.com'
}
}
scm {
connection = 'scm:https://github.com/orienteering-oss/iof-xml.git'
developerConnection = 'scm:https://github.com/orienteering-oss/iof-xml.git'
url = 'https://github.com/orienteering-oss/iof-xml'
}
}
}
}
repositories {
maven {
name = "sonatype"
def releaseRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotRepo = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
url = isReleaseVersion ? releaseRepo : snapshotRepo
//url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = ossrhUsername // maybe use findProperty("ossrhUsername") ?
password = ossrhPassword
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
tasks.withType(Sign) {
onlyIf { isReleaseVersion }
}
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
dokkaHtml {
dokkaSourceSets {
configureEach {
// See https://kotlin.github.io/dokka/1.7.10/user_guide/gradle/usage/#configuration-options
includes.from("src/main/README.md")
samples.from("src/test/kotlin/iofXml")
}
}
}
mainClassName = "${archivesBaseName}.MainKt"
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of("11"))
}
}