|
1 | | -@file:Suppress("UnstableApiUsage") |
2 | | - |
3 | | -import java.net.URL |
4 | | -import org.jetbrains.dokka.DokkaConfiguration.Visibility.PUBLIC |
5 | | -import org.jetbrains.dokka.gradle.DokkaTask |
6 | | - |
7 | 1 | plugins { |
8 | | - id("org.jetbrains.kotlin.jvm") version "1.8.21" |
9 | | - id("org.jetbrains.dokka") version "1.8.10" |
10 | | - id("org.openapi.generator") version "6.5.0" |
11 | | - `java-library` |
12 | | - `java-test-fixtures` |
13 | | - `maven-publish` |
14 | | -} |
15 | | - |
16 | | -group = "com.github.gabrielfeo" |
17 | | -val repoUrl = "https://github.com/gabrielfeo/gradle-enterprise-api-kotlin" |
18 | | - |
19 | | -val localSpecPath = providers.gradleProperty("localSpecPath") |
20 | | -val remoteSpecUrl = providers.gradleProperty("remoteSpecUrl").orElse( |
21 | | - providers.gradleProperty("gradle.enterprise.version").map { geVersion -> |
22 | | - val specName = "gradle-enterprise-$geVersion-api.yaml" |
23 | | - "https://docs.gradle.com/enterprise/api-manual/ref/$specName" |
24 | | - } |
25 | | -) |
26 | | - |
27 | | -val downloadApiSpec by tasks.registering { |
28 | | - onlyIf { !localSpecPath.isPresent() } |
29 | | - val spec = resources.text.fromUri(remoteSpecUrl) |
30 | | - val specName = remoteSpecUrl.map { it.substringAfterLast('/') } |
31 | | - val outFile = project.layout.buildDirectory.file(specName) |
32 | | - inputs.property("Spec URL", remoteSpecUrl) |
33 | | - outputs.file(outFile) |
34 | | - doLast { |
35 | | - logger.info("Downloaded API spec from ${remoteSpecUrl.get()}") |
36 | | - spec.asFile().renameTo(outFile.get().asFile) |
37 | | - } |
38 | | -} |
39 | | - |
40 | | -openApiGenerate { |
41 | | - generatorName.set("kotlin") |
42 | | - val spec = when { |
43 | | - localSpecPath.isPresent() -> localSpecPath.map { File(it).absolutePath } |
44 | | - else -> downloadApiSpec.map { it.outputs.files.first().absolutePath } |
45 | | - } |
46 | | - inputSpec.set(spec) |
47 | | - val generateDir = project.layout.buildDirectory.file("generated/openapi-generator") |
48 | | - outputDir.set(generateDir.map { it.asFile.absolutePath }) |
49 | | - val ignoreFile = project.layout.projectDirectory.file(".openapi-generator-ignore") |
50 | | - ignoreFileOverride.set(ignoreFile.asFile.absolutePath) |
51 | | - apiPackage.set("com.gabrielfeo.gradle.enterprise.api") |
52 | | - modelPackage.set("com.gabrielfeo.gradle.enterprise.api.model") |
53 | | - packageName.set("com.gabrielfeo.gradle.enterprise.api.internal") |
54 | | - invokerPackage.set("com.gabrielfeo.gradle.enterprise.api.internal") |
55 | | - additionalProperties.put("library", "jvm-retrofit2") |
56 | | - additionalProperties.put("useCoroutines", true) |
57 | | -} |
58 | | - |
59 | | -tasks.openApiGenerate.configure { |
60 | | - doFirst { |
61 | | - logger.info("Using API spec ${inputSpec.get()}") |
62 | | - } |
63 | | - // Replace Response<X> with X in every method return type of GradleEnterpriseApi.kt |
64 | | - doLast { |
65 | | - val apiFile = File( |
66 | | - outputDir.get(), |
67 | | - "src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt", |
68 | | - ) |
69 | | - ant.withGroovyBuilder { |
70 | | - "replaceregexp"( |
71 | | - "file" to apiFile, |
72 | | - "match" to ": Response<(.*?)>$", |
73 | | - "replace" to """: \1""", |
74 | | - "flags" to "gm", |
75 | | - ) |
76 | | - } |
77 | | - } |
78 | | - // Add @JvmSuppressWildcards to avoid square/retrofit#3275 |
79 | | - doLast { |
80 | | - val apiFile = File( |
81 | | - outputDir.get(), |
82 | | - "src/main/kotlin/com/gabrielfeo/gradle/enterprise/api/GradleEnterpriseApi.kt", |
83 | | - ) |
84 | | - ant.withGroovyBuilder { |
85 | | - "replaceregexp"( |
86 | | - "file" to apiFile, |
87 | | - "match" to "interface GradleEnterpriseApi", |
88 | | - "replace" to """ |
89 | | - @JvmSuppressWildcards |
90 | | - interface GradleEnterpriseApi |
91 | | - """.trimIndent(), |
92 | | - "flags" to "m", |
93 | | - ) |
94 | | - } |
95 | | - } |
96 | | - // Workaround for properties generated with `arrayListOf(null,null)` as default value |
97 | | - doLast { |
98 | | - val srcDir = File(outputDir.get(), "src/main/kotlin") |
99 | | - ant.withGroovyBuilder { |
100 | | - "replaceregexp"( |
101 | | - "match" to """arrayListOf\(null,null\)""", |
102 | | - "replace" to """emptyList()""", |
103 | | - "flags" to "gm", |
104 | | - ) { |
105 | | - "fileset"( |
106 | | - "dir" to srcDir |
107 | | - ) |
108 | | - } |
109 | | - } |
110 | | - } |
111 | | - // Workaround for missing imports of exploded queries |
112 | | - doLast { |
113 | | - val srcDir = File(outputDir.get(), "src/main/kotlin") |
114 | | - val modelPackage = openApiGenerate.modelPackage.get() |
115 | | - val modelPackagePattern = modelPackage.replace(".", "\\.") |
116 | | - ant.withGroovyBuilder { |
117 | | - "replaceregexp"( |
118 | | - "match" to """(?:import $modelPackagePattern.[.\w]+\s)+""", |
119 | | - "replace" to "import $modelPackage.*\n", |
120 | | - "flags" to "m", |
121 | | - ) { |
122 | | - "fileset"( |
123 | | - "dir" to srcDir |
124 | | - ) |
125 | | - } |
126 | | - } |
127 | | - } |
| 2 | + id("org.jetbrains.kotlin.jvm") version "1.8.21" apply false |
| 3 | + id("org.jetbrains.dokka") version "1.8.10" apply false |
| 4 | + id("org.openapi.generator") version "6.5.0" apply false |
128 | 5 | } |
129 | 6 |
|
130 | | -sourceSets { |
131 | | - main { |
132 | | - java { |
133 | | - srcDir(tasks.openApiGenerate) |
134 | | - } |
135 | | - } |
136 | | -} |
137 | | - |
138 | | -java { |
139 | | - withSourcesJar() |
140 | | - withJavadocJar() |
141 | | - toolchain { |
142 | | - languageVersion.set(JavaLanguageVersion.of(8)) |
143 | | - } |
144 | | -} |
145 | | - |
146 | | -components.getByName<AdhocComponentWithVariants>("java").apply { |
147 | | - withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() } |
148 | | - withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() } |
149 | | -} |
150 | | - |
151 | | -tasks.withType<DokkaTask>().configureEach { |
152 | | - dokkaSourceSets.all { |
153 | | - sourceLink { |
154 | | - localDirectory.set(file("src/main/kotlin")) |
155 | | - remoteUrl.set(URL("$repoUrl/blob/$version/src/main/kotlin")) |
156 | | - remoteLineSuffix.set("#L") |
157 | | - } |
158 | | - jdkVersion.set(8) |
159 | | - suppressGeneratedFiles.set(false) |
160 | | - documentedVisibilities.set(setOf(PUBLIC)) |
161 | | - perPackageOption { |
162 | | - matchingRegex.set(""".*\.internal.*""") |
163 | | - suppress.set(true) |
164 | | - } |
165 | | - externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/") |
166 | | - externalDocumentationLink("https://square.github.io/okhttp/4.x/okhttp/") |
167 | | - externalDocumentationLink("https://square.github.io/retrofit/2.x/retrofit/") |
168 | | - externalDocumentationLink("https://square.github.io/moshi/1.x/moshi/") |
169 | | - externalDocumentationLink("https://square.github.io/moshi/1.x/moshi-kotlin/") |
170 | | - } |
171 | | -} |
172 | | - |
173 | | -tasks.named<Jar>("javadocJar") { |
174 | | - from(tasks.dokkaHtml) |
175 | | -} |
176 | | - |
177 | | -publishing { |
178 | | - publications { |
179 | | - create<MavenPublication>("library") { |
180 | | - artifactId = "gradle-enterprise-api-kotlin" |
181 | | - from(components["java"]) |
182 | | - } |
183 | | - } |
184 | | -} |
185 | | - |
186 | | -testing { |
187 | | - suites { |
188 | | - getByName<JvmTestSuite>("test") { |
189 | | - dependencies { |
190 | | - implementation("com.squareup.okhttp3:mockwebserver:4.11.0") |
191 | | - implementation("com.squareup.okio:okio:3.3.0") |
192 | | - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1") |
193 | | - } |
194 | | - } |
195 | | - register<JvmTestSuite>("integrationTest") { |
196 | | - dependencies { |
197 | | - implementation(project()) |
198 | | - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1") |
199 | | - } |
200 | | - } |
201 | | - withType<JvmTestSuite> { |
202 | | - useKotlinTest() |
203 | | - } |
204 | | - } |
205 | | -} |
206 | | - |
207 | | -java { |
208 | | - consistentResolution { |
209 | | - useRuntimeClasspathVersions() |
210 | | - } |
211 | | -} |
| 7 | +val group by project.properties |
| 8 | +val artifact by project.properties |
212 | 9 |
|
213 | | -dependencies { |
214 | | - constraints { |
215 | | - implementation("com.squareup.okio:okio:3.3.0") |
| 10 | +project(":examples:example-project:app").configurations.configureEach { |
| 11 | + resolutionStrategy.dependencySubstitution { |
| 12 | + substitute(module("$group:$artifact")) |
| 13 | + .using(project(":library")) |
216 | 14 | } |
217 | | - api("com.squareup.moshi:moshi:1.15.0") |
218 | | - implementation("com.squareup.moshi:moshi-kotlin:1.15.0") |
219 | | - api("com.squareup.okhttp3:okhttp:4.11.0") |
220 | | - implementation("com.squareup.okhttp3:logging-interceptor:4.11.0") |
221 | | - api("com.squareup.retrofit2:retrofit:2.9.0") |
222 | | - implementation("com.squareup.retrofit2:converter-moshi:2.9.0") |
223 | | - implementation("com.squareup.retrofit2:converter-scalars:2.9.0") |
224 | | - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1") |
225 | 15 | } |
0 commit comments