1 /*
2 * Copyright (C) 2020 Square, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import com.diffplug.gradle.spotless.JavaExtension
18 import com.vanniktech.maven.publish.MavenPublishBaseExtension
19 import com.vanniktech.maven.publish.SonatypeHost
20 import org.jetbrains.dokka.gradle.DokkaTask
21 import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
22 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23 import java.net.URL
24
<lambda>null25 buildscript {
26 dependencies {
27 val kotlinVersion = System.getenv("MOSHI_KOTLIN_VERSION")
28 ?: libs.versions.kotlin.get()
29 val kspVersion = System.getenv("MOSHI_KSP_VERSION")
30 ?: libs.versions.ksp.get()
31 classpath(kotlin("gradle-plugin", version = kotlinVersion))
32 classpath("com.google.devtools.ksp:symbol-processing-gradle-plugin:$kspVersion")
33 // https://github.com/melix/japicmp-gradle-plugin/issues/36
34 classpath("com.google.guava:guava:28.2-jre")
35 }
36 }
37
<lambda>null38 plugins {
39 alias(libs.plugins.mavenPublish)
40 alias(libs.plugins.dokka) apply false
41 alias(libs.plugins.spotless)
42 alias(libs.plugins.japicmp) apply false
43 }
44
<lambda>null45 allprojects {
46 group = "com.squareup.moshi"
47 version = "1.15.1"
48
49 repositories {
50 mavenCentral()
51 }
52 }
53
<lambda>null54 spotless {
55 format("misc") {
56 target("*.md", ".gitignore")
57 trimTrailingWhitespace()
58 indentWithSpaces(2)
59 endWithNewline()
60 }
61 val configureCommonJavaFormat: JavaExtension.() -> Unit = {
62 googleJavaFormat(libs.versions.gjf.get())
63 }
64 java {
65 configureCommonJavaFormat()
66 target("**/*.java")
67 targetExclude(
68 "**/build/**",
69 "**/RecordsTest.java",
70 "**/RecordJsonAdapter.java",
71 )
72 }
73 kotlin {
74 ktlint(libs.versions.ktlint.get()).userData(mapOf("indent_size" to "2"))
75 target("**/*.kt")
76 trimTrailingWhitespace()
77 endWithNewline()
78 targetExclude("**/Dependencies.kt", "**/build/**")
79 }
80 kotlinGradle {
81 ktlint(libs.versions.ktlint.get()).userData(mapOf("indent_size" to "2"))
82 target("**/*.gradle.kts")
83 trimTrailingWhitespace()
84 endWithNewline()
85 }
86 }
87
<lambda>null88 subprojects {
89 // Apply with "java" instead of just "java-library" so kotlin projects get it too
90 pluginManager.withPlugin("java") {
91 configure<JavaPluginExtension> {
92 toolchain {
93 languageVersion.set(JavaLanguageVersion.of(17))
94 }
95 }
96 if (project.name != "records-tests") {
97 tasks.withType<JavaCompile>().configureEach {
98 options.release.set(8)
99 }
100 }
101 }
102
103 pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
104 tasks.withType<KotlinCompile>().configureEach {
105 kotlinOptions {
106 // TODO re-enable when no longer supporting multiple kotlin versions
107 // @Suppress("SuspiciousCollectionReassignment")
108 // freeCompilerArgs += listOf("-progressive")
109 jvmTarget = libs.versions.jvmTarget.get()
110 }
111 }
112
113 configure<KotlinProjectExtension> {
114 if (project.name != "examples") {
115 explicitApi()
116 }
117 }
118 }
119 }
120
<lambda>null121 allprojects {
122 tasks.withType<DokkaTask>().configureEach {
123 dokkaSourceSets.configureEach {
124 reportUndocumented.set(false)
125 skipDeprecated.set(true)
126 jdkVersion.set(8)
127 perPackageOption {
128 matchingRegex.set("com\\.squareup.moshi\\.internal.*")
129 suppress.set(true)
130 }
131 }
132 if (name == "dokkaHtml") {
133 outputDirectory.set(rootDir.resolve("docs/1.x"))
134 dokkaSourceSets.configureEach {
135 skipDeprecated.set(true)
136 externalDocumentationLink {
137 url.set(URL("https://square.github.io/okio/2.x/okio/"))
138 }
139 }
140 }
141 }
142
143 plugins.withId("com.vanniktech.maven.publish.base") {
144 configure<MavenPublishBaseExtension> {
145 publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
146 signAllPublications()
147 pom {
148 description.set("A modern JSON API for Android and Java")
149 name.set(project.name)
150 url.set("https://github.com/square/moshi/")
151 licenses {
152 license {
153 name.set("The Apache Software License, Version 2.0")
154 url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
155 distribution.set("repo")
156 }
157 }
158 scm {
159 url.set("https://github.com/square/moshi/")
160 connection.set("scm:git:git://github.com/square/moshi.git")
161 developerConnection.set("scm:git:ssh://[email protected]/square/moshi.git")
162 }
163 developers {
164 developer {
165 id.set("square")
166 name.set("Square, Inc.")
167 }
168 }
169 }
170 }
171 }
172 }
173