1*238ab3e7SAndroid Build Coastguard Worker /*
2*238ab3e7SAndroid Build Coastguard Worker * Copyright (C) 2020 Square, Inc.
3*238ab3e7SAndroid Build Coastguard Worker *
4*238ab3e7SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*238ab3e7SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*238ab3e7SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*238ab3e7SAndroid Build Coastguard Worker *
8*238ab3e7SAndroid Build Coastguard Worker * https://www.apache.org/licenses/LICENSE-2.0
9*238ab3e7SAndroid Build Coastguard Worker *
10*238ab3e7SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*238ab3e7SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*238ab3e7SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*238ab3e7SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*238ab3e7SAndroid Build Coastguard Worker * limitations under the License.
15*238ab3e7SAndroid Build Coastguard Worker */
16*238ab3e7SAndroid Build Coastguard Worker
17*238ab3e7SAndroid Build Coastguard Worker import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
18*238ab3e7SAndroid Build Coastguard Worker import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
19*238ab3e7SAndroid Build Coastguard Worker import com.vanniktech.maven.publish.JavadocJar.Empty
20*238ab3e7SAndroid Build Coastguard Worker import com.vanniktech.maven.publish.KotlinJvm
21*238ab3e7SAndroid Build Coastguard Worker import com.vanniktech.maven.publish.MavenPublishBaseExtension
22*238ab3e7SAndroid Build Coastguard Worker import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23*238ab3e7SAndroid Build Coastguard Worker
<lambda>null24*238ab3e7SAndroid Build Coastguard Worker plugins {
25*238ab3e7SAndroid Build Coastguard Worker kotlin("jvm")
26*238ab3e7SAndroid Build Coastguard Worker id("com.google.devtools.ksp")
27*238ab3e7SAndroid Build Coastguard Worker id("com.vanniktech.maven.publish.base")
28*238ab3e7SAndroid Build Coastguard Worker alias(libs.plugins.mavenShadow)
29*238ab3e7SAndroid Build Coastguard Worker }
30*238ab3e7SAndroid Build Coastguard Worker
<lambda>null31*238ab3e7SAndroid Build Coastguard Worker tasks.withType<KotlinCompile>().configureEach {
32*238ab3e7SAndroid Build Coastguard Worker kotlinOptions {
33*238ab3e7SAndroid Build Coastguard Worker @Suppress("SuspiciousCollectionReassignment")
34*238ab3e7SAndroid Build Coastguard Worker freeCompilerArgs += listOf(
35*238ab3e7SAndroid Build Coastguard Worker "-opt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
36*238ab3e7SAndroid Build Coastguard Worker "-opt-in=com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi",
37*238ab3e7SAndroid Build Coastguard Worker )
38*238ab3e7SAndroid Build Coastguard Worker if (this@configureEach.name == "compileTestKotlin") {
39*238ab3e7SAndroid Build Coastguard Worker freeCompilerArgs += "-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi"
40*238ab3e7SAndroid Build Coastguard Worker }
41*238ab3e7SAndroid Build Coastguard Worker }
42*238ab3e7SAndroid Build Coastguard Worker }
43*238ab3e7SAndroid Build Coastguard Worker
44*238ab3e7SAndroid Build Coastguard Worker // --add-opens for kapt to work. KGP covers this for us but local JVMs in tests do not
<lambda>null45*238ab3e7SAndroid Build Coastguard Worker tasks.withType<Test>().configureEach {
46*238ab3e7SAndroid Build Coastguard Worker jvmArgs(
47*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
48*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
49*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
50*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
51*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED",
52*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
53*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
54*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
55*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
56*238ab3e7SAndroid Build Coastguard Worker "--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
57*238ab3e7SAndroid Build Coastguard Worker )
58*238ab3e7SAndroid Build Coastguard Worker }
59*238ab3e7SAndroid Build Coastguard Worker
60*238ab3e7SAndroid Build Coastguard Worker val shade: Configuration = configurations.maybeCreate("compileShaded")
61*238ab3e7SAndroid Build Coastguard Worker configurations.getByName("compileOnly").extendsFrom(shade)
<lambda>null62*238ab3e7SAndroid Build Coastguard Worker dependencies {
63*238ab3e7SAndroid Build Coastguard Worker implementation(project(":moshi"))
64*238ab3e7SAndroid Build Coastguard Worker implementation(kotlin("reflect"))
65*238ab3e7SAndroid Build Coastguard Worker shade(libs.kotlinxMetadata) {
66*238ab3e7SAndroid Build Coastguard Worker exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
67*238ab3e7SAndroid Build Coastguard Worker }
68*238ab3e7SAndroid Build Coastguard Worker api(libs.kotlinpoet)
69*238ab3e7SAndroid Build Coastguard Worker shade(libs.kotlinpoet.metadata) {
70*238ab3e7SAndroid Build Coastguard Worker exclude(group = "org.jetbrains.kotlin")
71*238ab3e7SAndroid Build Coastguard Worker exclude(group = "com.squareup", module = "kotlinpoet")
72*238ab3e7SAndroid Build Coastguard Worker exclude(group = "com.google.guava")
73*238ab3e7SAndroid Build Coastguard Worker }
74*238ab3e7SAndroid Build Coastguard Worker implementation(libs.kotlinpoet.ksp)
75*238ab3e7SAndroid Build Coastguard Worker implementation(libs.guava)
76*238ab3e7SAndroid Build Coastguard Worker implementation(libs.asm)
77*238ab3e7SAndroid Build Coastguard Worker implementation(platform(libs.kotlin.bom))
78*238ab3e7SAndroid Build Coastguard Worker
79*238ab3e7SAndroid Build Coastguard Worker implementation(libs.autoService)
80*238ab3e7SAndroid Build Coastguard Worker ksp(libs.autoService.ksp)
81*238ab3e7SAndroid Build Coastguard Worker
82*238ab3e7SAndroid Build Coastguard Worker // KSP deps
83*238ab3e7SAndroid Build Coastguard Worker compileOnly(libs.ksp)
84*238ab3e7SAndroid Build Coastguard Worker compileOnly(libs.ksp.api)
85*238ab3e7SAndroid Build Coastguard Worker compileOnly(libs.kotlin.annotationProcessingEmbeddable)
86*238ab3e7SAndroid Build Coastguard Worker compileOnly(libs.kotlin.compilerEmbeddable)
87*238ab3e7SAndroid Build Coastguard Worker compileOnly(platform(libs.kotlin.bom))
88*238ab3e7SAndroid Build Coastguard Worker // Always force the latest KSP version to match the one we're compiling against
89*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.ksp)
90*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.ksp.api)
91*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.kotlin.annotationProcessingEmbeddable)
92*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.kotlin.compilerEmbeddable)
93*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.kotlinCompileTesting.ksp)
94*238ab3e7SAndroid Build Coastguard Worker testImplementation(platform(libs.kotlin.bom))
95*238ab3e7SAndroid Build Coastguard Worker
96*238ab3e7SAndroid Build Coastguard Worker // Copy these again as they're not automatically included since they're shaded
97*238ab3e7SAndroid Build Coastguard Worker testImplementation(project(":moshi"))
98*238ab3e7SAndroid Build Coastguard Worker testImplementation(kotlin("reflect"))
99*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.kotlinpoet.metadata)
100*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.kotlinpoet.ksp)
101*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.junit)
102*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.truth)
103*238ab3e7SAndroid Build Coastguard Worker testImplementation(libs.kotlinCompileTesting)
104*238ab3e7SAndroid Build Coastguard Worker }
105*238ab3e7SAndroid Build Coastguard Worker
<lambda>null106*238ab3e7SAndroid Build Coastguard Worker val relocateShadowJar = tasks.register<ConfigureShadowRelocation>("relocateShadowJar") {
107*238ab3e7SAndroid Build Coastguard Worker target = tasks.shadowJar.get()
108*238ab3e7SAndroid Build Coastguard Worker }
109*238ab3e7SAndroid Build Coastguard Worker
<lambda>null110*238ab3e7SAndroid Build Coastguard Worker val shadowJar = tasks.shadowJar.apply {
111*238ab3e7SAndroid Build Coastguard Worker configure {
112*238ab3e7SAndroid Build Coastguard Worker dependsOn(relocateShadowJar)
113*238ab3e7SAndroid Build Coastguard Worker archiveClassifier.set("")
114*238ab3e7SAndroid Build Coastguard Worker configurations = listOf(shade)
115*238ab3e7SAndroid Build Coastguard Worker relocate("com.squareup.kotlinpoet.metadata", "com.squareup.moshi.kotlinpoet.metadata")
116*238ab3e7SAndroid Build Coastguard Worker relocate(
117*238ab3e7SAndroid Build Coastguard Worker "com.squareup.kotlinpoet.classinspector",
118*238ab3e7SAndroid Build Coastguard Worker "com.squareup.moshi.kotlinpoet.classinspector"
119*238ab3e7SAndroid Build Coastguard Worker )
120*238ab3e7SAndroid Build Coastguard Worker relocate("kotlinx.metadata", "com.squareup.moshi.kotlinx.metadata")
121*238ab3e7SAndroid Build Coastguard Worker transformers.add(ServiceFileTransformer())
122*238ab3e7SAndroid Build Coastguard Worker }
123*238ab3e7SAndroid Build Coastguard Worker }
124*238ab3e7SAndroid Build Coastguard Worker
<lambda>null125*238ab3e7SAndroid Build Coastguard Worker artifacts {
126*238ab3e7SAndroid Build Coastguard Worker runtimeOnly(shadowJar)
127*238ab3e7SAndroid Build Coastguard Worker archives(shadowJar)
128*238ab3e7SAndroid Build Coastguard Worker }
129*238ab3e7SAndroid Build Coastguard Worker
<lambda>null130*238ab3e7SAndroid Build Coastguard Worker configure<MavenPublishBaseExtension> {
131*238ab3e7SAndroid Build Coastguard Worker configure(KotlinJvm(javadocJar = Empty()))
132*238ab3e7SAndroid Build Coastguard Worker }
133