|
| 1 | + |
| 2 | +plugins { |
| 3 | + id("java") |
| 4 | + id("maven-publish") |
| 5 | + alias(libs.plugins.openapi) |
| 6 | + alias(libs.plugins.spotless) |
| 7 | +} |
| 8 | + |
| 9 | +// Some text from the schema is copy/pasted into the source files as UTF-8 |
| 10 | +// but the default still seems to be to use platform encoding |
| 11 | +tasks.withType<JavaCompile>().configureEach { |
| 12 | + sourceCompatibility = "11" |
| 13 | + targetCompatibility = "11" |
| 14 | + |
| 15 | + options.encoding = "UTF-8" |
| 16 | +} |
| 17 | + |
| 18 | +tasks.withType<Javadoc>().configureEach { |
| 19 | + options.encoding = "UTF-8" |
| 20 | +} |
| 21 | + |
| 22 | +java { |
| 23 | + withSourcesJar() |
| 24 | +} |
| 25 | + |
| 26 | +tasks.register<Jar>("javadocJar") { |
| 27 | + archiveClassifier = "javadoc" |
| 28 | + from(tasks.javadoc.get().destinationDir) |
| 29 | + dependsOn(tasks.javadoc) |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +publishing { |
| 34 | + publications { |
| 35 | + create<MavenPublication>(project.name) { |
| 36 | + artifactId = project.name |
| 37 | + from(components["java"]) |
| 38 | + artifact(tasks["javadocJar"]) |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +val jacksonVersion = libs.versions.jackson.get() |
| 44 | +val jakartaAnnotationVersion = libs.versions.jakarta.annotation.get() |
| 45 | + |
| 46 | +ext { |
| 47 | + description = "OpenZiti Edge API client" |
| 48 | +} |
| 49 | + |
| 50 | +dependencies { |
| 51 | + implementation("com.google.code.findbugs:jsr305:3.0.2") |
| 52 | + implementation(libs.jackson.core) |
| 53 | + implementation(libs.jackson.annotations) |
| 54 | + implementation(libs.jackson.bind) |
| 55 | + implementation(libs.jackson.datatype) |
| 56 | + implementation("org.openapitools:jackson-databind-nullable:0.2.6") |
| 57 | + implementation("jakarta.annotation:jakarta.annotation-api:$jakartaAnnotationVersion") |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +// generate Ziti Edge API client |
| 62 | +// only needed if new version was published in github.com/openziti/edge-api |
| 63 | +// run `./gradlew :openApiGenerate`, check build, commit, push |
| 64 | +val edgeApiVersion = libs.versions.ziti.api.get() |
| 65 | + |
| 66 | +openApiGenerate { |
| 67 | + applyDefaults() |
| 68 | + |
| 69 | + remoteInputSpec.set("https://raw.githubusercontent.com/openziti/edge-api/v${edgeApiVersion}/client.yml") |
| 70 | + version.set(project.version.toString()) |
| 71 | + outputDir.set("$projectDir") |
| 72 | + generatorName.set("java") |
| 73 | + groupId.set("org.openziti") |
| 74 | + id.set("edge-api") |
| 75 | + modelPackage.set("org.openziti.edge.model") |
| 76 | + apiPackage.set("org.openziti.edge.api") |
| 77 | + generateModelTests.set(false) |
| 78 | + generateApiTests.set(false) |
| 79 | + configOptions = mapOf( |
| 80 | + "dateLibrary" to "java8", |
| 81 | + "library" to "native", |
| 82 | + "asyncNative" to true.toString(), |
| 83 | + ) |
| 84 | +} |
| 85 | + |
| 86 | + |
| 87 | +tasks.named("openApiGenerate").get().finalizedBy("spotlessApply") |
| 88 | +// Use spotless plugin to automatically format code, remove unused import, etc |
| 89 | +// To apply changes directly to the file, run `gradlew spotlessApply` |
| 90 | +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle |
| 91 | +spotless { |
| 92 | + // comment out below to run spotless as part of the `check` task |
| 93 | +// enforceCheck = false |
| 94 | + format("misc") { |
| 95 | + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to |
| 96 | + target(".gitignore") |
| 97 | + // define the steps to apply to those files |
| 98 | + trimTrailingWhitespace() |
| 99 | + leadingTabsToSpaces() // Takes an integer argument if you don't like 4 |
| 100 | + endWithNewline() |
| 101 | + } |
| 102 | + java { |
| 103 | + // don't need to set target, it is inferred from java |
| 104 | + // apply a specific flavor of google-java-format |
| 105 | + googleJavaFormat("1.22.0").aosp().reflowLongStrings() |
| 106 | + removeUnusedImports() |
| 107 | + importOrder() |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +tasks.named("spotlessApply").get().mustRunAfter("openApiGenerate") |
| 113 | +tasks.named("spotlessJava").get().mustRunAfter("openApiGenerate") |
| 114 | +tasks.named("spotlessMisc").get().mustRunAfter("openApiGenerate") |
| 115 | + |
| 116 | +apply(from = rootProject.file("publish.gradle")) |
| 117 | + |
| 118 | + |
0 commit comments