|
| 1 | +import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
| 2 | + |
1 | 3 | plugins { |
| 4 | + `java-library` |
2 | 5 | groovy |
3 | | - id("maven-publish") |
4 | | - id("signing") |
5 | | - id("org.jetbrains.kotlin.jvm") version("1.4.30") |
6 | | - id("com.github.ben-manes.versions") version ("0.36.0") |
| 6 | + kotlin |
| 7 | + jacoco |
| 8 | + alias(libs.plugins.updates) |
| 9 | + id("openapiprocessor.test") |
| 10 | + id("openapiprocessor.testInt") |
| 11 | + id("openapiprocessor.publish") |
| 12 | + id("jacoco-report-aggregation") |
7 | 13 | } |
8 | 14 |
|
9 | 15 | val projectGroupId: String by project |
10 | 16 | val projectVersion: String by project |
11 | 17 |
|
12 | | -group = projectGroupId |
13 | | -version = projectVersion |
14 | | - |
15 | | -tasks.compileKotlin { |
16 | | - kotlinOptions.jvmTarget = "1.8" |
17 | | -} |
18 | | - |
19 | | -fun getBuildProperty(property: String): String { |
20 | | - val prop: String? = project.findProperty(property) as String? |
21 | | - if(prop != null) { |
22 | | - return prop |
23 | | - } |
24 | | - |
25 | | - val env: String? = System.getenv(property) |
26 | | - if (env != null) { |
27 | | - return env |
28 | | - } |
| 18 | +group = "io.openapiprocessor" |
| 19 | +version = libs.versions.processor.get() |
| 20 | +println("version: $version") |
29 | 21 |
|
30 | | - return "n/a" |
| 22 | +java { |
| 23 | + withJavadocJar () |
| 24 | + withSourcesJar () |
31 | 25 | } |
32 | 26 |
|
33 | | -fun getBuildSignKey(property: String): String { |
34 | | - val prop: String? = project.findProperty(property) as String? |
35 | | - if(prop != null) { |
36 | | - return prop |
37 | | - } |
| 27 | +kotlin { |
| 28 | + jvmToolchain(libs.versions.build.jdk.get().toInt()) |
38 | 29 |
|
39 | | - val env: String? = System.getenv(property) |
40 | | - if (env != null) { |
41 | | - return env.replace("\\n", "\n") |
| 30 | + compilerOptions { |
| 31 | + freeCompilerArgs.add("-Xannotation-default-target=param-property") |
| 32 | + jvmTarget = JvmTarget.fromTarget(libs.versions.target.jdk.get()) |
42 | 33 | } |
43 | | - |
44 | | - return "n/a" |
45 | | -} |
46 | | - |
47 | | -fun isReleaseVersion(): Boolean { |
48 | | - return !(project.version.toString().endsWith("SNAPSHOT")) |
49 | | -} |
50 | | - |
51 | | -project.ext { |
52 | | - set("processorApiVersion", "2021.1") |
53 | | - |
54 | | - set("publishUser", getBuildProperty("PUBLISH_USER")) |
55 | | - set("publishKey", getBuildProperty("PUBLISH_KEY")) |
56 | | - set("signKey", getBuildSignKey("SIGN_KEY")) |
57 | | - set("signPwd", getBuildProperty("SIGN_PWD")) |
58 | 34 | } |
59 | 35 |
|
60 | | - |
61 | | -repositories { |
62 | | - mavenCentral() |
63 | | - maven { |
64 | | - setUrl("https://oss.sonatype.org/content/repositories/snapshots") |
65 | | - mavenContent { |
66 | | - snapshotsOnly() |
67 | | - } |
68 | | - } |
69 | | - jcenter() |
| 36 | +tasks.compileTestGroovy { |
| 37 | + classpath += sourceSets.main.get().compileClasspath |
| 38 | + classpath += files(tasks.compileKotlin.get().destinationDirectory) |
| 39 | + classpath += files(tasks.compileTestKotlin.get().destinationDirectory) |
70 | 40 | } |
71 | 41 |
|
72 | 42 | dependencies { |
73 | | - implementation(kotlin("stdlib-jdk8")) |
| 43 | + implementation (libs.openapi.processor.api) |
74 | 44 |
|
75 | 45 | implementation("io.swagger.parser.v3:swagger-parser:2.0.24") { |
76 | 46 | exclude(group = "io.swagger.parser.v3", module = "swagger-parser-v2-converter") |
77 | 47 | exclude(group = "io.swagger.core.v3", module = "swagger-annotations") |
78 | 48 | } |
79 | | - compileOnly("io.openapiprocessor:openapi-processor-api:${project.ext.get("processorApiVersion")}") |
80 | | - |
81 | | - testImplementation("net.bytebuddy:byte-buddy:1.10.20") |
82 | | - testImplementation("org.spockframework:spock-core:1.3-groovy-2.5") { |
83 | | - exclude(group = "org.codehaus.groovy", module = "groovy-json") |
84 | | - exclude(group = "org.codehaus.groovy", module = "groovy-macro") |
85 | | - exclude(group = "org.codehaus.groovy", module = "groovy-sql") |
86 | | - exclude(group = "org.codehaus.groovy", module = "groovy-templates") |
87 | | - exclude(group = "org.codehaus.groovy", module = "groovy-xml") |
88 | | - } |
89 | | - testImplementation("io.github.java-diff-utils:java-diff-utils:4.9") |
90 | | - testImplementation("io.openapiprocessor:openapi-processor-api:${project.ext.get("processorApiVersion")}") |
91 | | -} |
92 | | - |
93 | | -tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { |
94 | | - kotlinOptions.jvmTarget = "1.8" |
95 | | -} |
96 | | - |
97 | | -tasks.withType<GroovyCompile> { |
98 | | - dependsOn("compileKotlin") |
99 | | - classpath += files(tasks.compileKotlin.get().destinationDir) |
100 | | -} |
101 | | - |
102 | | -val sourcesJar by tasks.registering(Jar::class) { |
103 | | - archiveClassifier.set("sources") |
104 | | - from(sourceSets.main.get().allSource) |
105 | | -} |
106 | | - |
107 | | -val javadocJar by tasks.registering(Jar::class) { |
108 | | - dependsOn("javadoc") |
109 | | - archiveClassifier.set("javadoc") |
110 | | - from(tasks.javadoc.get().destinationDir) |
111 | | -} |
112 | | - |
113 | | -artifacts { |
114 | | - archives(sourcesJar) |
115 | | - archives(javadocJar) |
116 | | -} |
117 | | - |
118 | | - |
119 | | -val projectTitle: String by project |
120 | | -val projectDesc: String by project |
121 | | -val projectUrl: String by project |
122 | | -val projectGithubRepo: String by project |
123 | | - |
124 | | -// does not work on oss.sonatype.org |
125 | | -tasks.withType<GenerateModuleMetadata>().configureEach { |
126 | | - enabled = false |
127 | | -} |
128 | | - |
129 | | -publishing { |
130 | | - publications { |
131 | | - create<MavenPublication>("OpenApiProcessor") { |
132 | | - from(components["java"]) |
133 | | - artifact(sourcesJar.get()) |
134 | | - artifact(javadocJar.get()) |
135 | | - |
136 | | - groupId = project.group.toString() |
137 | | - artifactId = project.name |
138 | | - version = project.version.toString() |
139 | | - |
140 | | - pom { |
141 | | - name.set(projectTitle) |
142 | | - description.set(projectDesc) |
143 | | - url.set(projectUrl) |
144 | | - |
145 | | - licenses { |
146 | | - license { |
147 | | - name.set("The Apache License, Version 2.0") |
148 | | - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") |
149 | | - distribution.set("repo") |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - developers { |
154 | | - developer { |
155 | | - id.set("hauner") |
156 | | - name.set("Martin Hauner") |
157 | | - } |
158 | | - } |
159 | | - |
160 | | - scm { |
161 | | - url.set("https://github.com/${projectGithubRepo}") |
162 | | - } |
163 | | - } |
164 | | - } |
165 | | - } |
166 | | - |
167 | | - repositories { |
168 | | - maven { |
169 | | - val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" |
170 | | - val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" |
171 | | - url = uri(if (isReleaseVersion()) releasesRepoUrl else snapshotsRepoUrl) |
172 | | - |
173 | | - credentials { |
174 | | - username = project.extra["publishUser"].toString() |
175 | | - password = project.extra["publishKey"].toString() |
176 | | - } |
177 | | - } |
178 | | - } |
179 | | -} |
180 | | - |
181 | | -//tasks.withType<Sign>().configureEach { |
182 | | -// onlyIf { isReleaseVersion() } |
183 | | -//} |
184 | | - |
185 | | -signing { |
186 | | - useInMemoryPgpKeys( |
187 | | - project.extra["signKey"].toString(), |
188 | | - project.extra["signPwd"].toString()) |
189 | | - |
190 | | - sign(publishing.publications["OpenApiProcessor"]) |
191 | | -} |
192 | 49 |
|
193 | | - |
194 | | -registerPublishTask("snapshot") { hasSnapshotVersion() } |
195 | | -registerPublishTask("release") { !hasSnapshotVersion() } |
196 | | - |
197 | | -fun registerPublishTask(type: String, condition: () -> Boolean) { |
198 | | - tasks.register("publish${type.capitalize()}") { |
199 | | - group = "publishing" |
200 | | - description = "Publish only if the current version is a ${type.capitalize()} version" |
201 | | - |
202 | | - if (condition()) { |
203 | | - println("enabling $type publishing") |
204 | | - dependsOn(tasks.withType<PublishToMavenRepository>()) |
205 | | - } else { |
206 | | - doLast { |
207 | | - println("skipping - no $type version") |
208 | | - } |
209 | | - } |
| 50 | + testImplementation("io.github.java-diff-utils:java-diff-utils:4.9") |
| 51 | + testImplementation (platform(libs.groovy.bom)) |
| 52 | + testImplementation ("org.apache.groovy:groovy") |
| 53 | + testImplementation ("org.apache.groovy:groovy-nio") |
| 54 | + testImplementation (libs.spock) |
| 55 | + testImplementation (platform(libs.kotest.bom)) |
| 56 | + testImplementation (libs.kotest.runner) |
| 57 | + testImplementation (libs.kotest.table) |
| 58 | + testImplementation (libs.mockk) |
| 59 | + testImplementation (libs.logback) |
| 60 | + |
| 61 | + testIntImplementation("io.github.java-diff-utils:java-diff-utils:4.9") |
| 62 | + testIntImplementation (platform(libs.groovy.bom)) |
| 63 | + testIntImplementation ("org.apache.groovy:groovy") |
| 64 | + testIntImplementation ("org.apache.groovy:groovy-nio") |
| 65 | + testIntImplementation (libs.spock) |
| 66 | + testIntImplementation (platform(libs.kotest.bom)) |
| 67 | + testIntImplementation (libs.kotest.runner) |
| 68 | + testIntImplementation (libs.kotest.table) |
| 69 | + testIntImplementation (libs.mockk) |
| 70 | + testIntImplementation (libs.logback) |
| 71 | +} |
| 72 | + |
| 73 | +tasks.withType<Test>().configureEach { |
| 74 | +// jvmArgs(listOf( |
| 75 | +// "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", |
| 76 | +// "--add-exports", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", |
| 77 | +// "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", |
| 78 | +// "--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", |
| 79 | +// "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", |
| 80 | +// "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" |
| 81 | +// )) |
| 82 | + |
| 83 | + finalizedBy(tasks.named("jacocoTestReport")) |
| 84 | +} |
| 85 | + |
| 86 | +jacoco { |
| 87 | + toolVersion = libs.versions.jacoco.get() |
| 88 | +} |
| 89 | + |
| 90 | +tasks.jacocoTestReport { |
| 91 | + executionData.from(tasks.named<Test>("test").map<File> { |
| 92 | + it.extensions.getByType(JacocoTaskExtension::class.java).destinationFile as File |
| 93 | + }) |
| 94 | + executionData.from(tasks.named<Test>("testInt").map<File> { |
| 95 | + it.extensions.getByType(JacocoTaskExtension::class.java).destinationFile as File |
| 96 | + }) |
| 97 | + |
| 98 | + reports { |
| 99 | + xml.required = true |
| 100 | + html.required = true |
210 | 101 | } |
211 | 102 | } |
212 | | - |
213 | | -fun hasSnapshotVersion(): Boolean { |
214 | | - return version.toString().endsWith("-SNAPSHOT") |
215 | | -} |
0 commit comments