forked from sandymist/interceptor-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
182 lines (151 loc) · 5.07 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.sandymist.mobile.android.gradle.internal.BootstrapAndroidSdk
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
plugins {
id("dev.gradleplugins.groovy-gradle-plugin") version BuildPluginsVersion.GROOVY_REDISTRIBUTED
kotlin("jvm") version BuildPluginsVersion.KOTLIN
id("distribution")
id("java-gradle-plugin")
id("groovy")
id("maven-publish")
// we need this plugin in order to include .aar dependencies into a pure java project, which the gradle plugin is
id("com.stepango.aar2jar") version BuildPluginsVersion.AAR_2_JAR
id("com.github.johnrengelman.shadow") version BuildPluginsVersion.SHADOW
id("com.gradle.plugin-publish") version "1.3.0"
}
repositories {
mavenCentral()
google()
}
group = "com.sandymist.mobile"
version = "0.1.3"
BootstrapAndroidSdk.locateAndroidSdk(project, extra)
val testImplementationAar by configurations.getting // this converts .aar into .jar dependencies
val agp74: SourceSet by sourceSets.creating
val shade: Configuration by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}
val fixtureClasspath: Configuration by configurations.creating
dependencies {
agp74.compileOnlyConfigurationName(Libs.GRADLE_API)
agp74.compileOnlyConfigurationName(Libs.agp("7.4.0"))
compileOnly(Libs.GRADLE_API)
compileOnly(Libs.AGP)
compileOnly(agp74.output)
compileOnly(Libs.PROGUARD)
compileOnly(Libs.ASM)
compileOnly(Libs.ASM_COMMONS)
testImplementation(gradleTestKit())
testImplementation(kotlin("test"))
testImplementation(Libs.AGP)
testImplementation(agp74.output)
fixtureClasspath(agp74.output)
testImplementation(Libs.PROGUARD)
testImplementation(Libs.JUNIT)
testImplementation(Libs.MOCKITO_KOTLIN)
testImplementation(Libs.ASM)
testImplementation(Libs.ASM_COMMONS)
}
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
// We need to compile Groovy first and let Kotlin depend on it.
// See https://docs.gradle.org/6.1-rc-1/release-notes.html#compilation-order
tasks.withType<GroovyCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
// we don't need the groovy compile task for compatibility source sets
val ignoreTask = name.contains("agp", ignoreCase = true)
isEnabled = !ignoreTask
if (!ignoreTask) {
classpath = sourceSets["main"].compileClasspath
}
}
tasks.withType<KotlinCompile>().configureEach {
if (!name.contains("agp", ignoreCase = true)) {
classpath += files(sourceSets["main"].groovy.classesDirectory)
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
freeCompilerArgs = listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xjvm-default=enable")
languageVersion = "1.4"
apiVersion = "1.4"
}
}
tasks.withType<Test>().configureEach {
maxParallelForks = Runtime.getRuntime().availableProcessors() / 2
}
gradlePlugin {
plugins {
register("interceptorPlugin") {
id = "com.sandymist.mobile.plugin.interceptor"
implementationClass = "com.sandymist.mobile.android.gradle.InterceptorPlugin"
displayName = "Interceptor Plugin for Android"
}
}
}
pluginBundle {
website = "https://github.com/sandymist/interceptor-plugin"
vcsUrl = "https://github.com/sandymist/interceptor-plugin"
description = "Network interceptor plugin for Android"
tags = listOf("android", "interceptor", "okhttp")
}
tasks.withType<Jar> {
from(agp74.output)
}
tasks.withType<ShadowJar> {
archiveClassifier.set("")
configurations = listOf(project.configurations.getByName("shade"))
exclude("/kotlin/**")
exclude("/groovy**")
exclude("/org/**")
}
artifacts {
runtimeOnly(tasks.named("shadowJar"))
archives(tasks.named("shadowJar"))
}
val sep = File.separator
distributions {
main {
contents {
from("build${sep}libs")
from("build${sep}publications${sep}maven")
}
}
create("interceptorPluginMarker") {
contents {
from("build${sep}publications${sep}interceptorPluginPluginMarkerMaven")
}
}
}
tasks.register<com.sandymist.mobile.android.gradle.internal.ASMifyTask>("asmify")
afterEvaluate {
publishing {
repositories {
maven {
println("VERS: " + project.version.toString())
name = "artifactory"
url = if (project.version.toString().endsWith("-SNAPSHOT")) {
uri(RepositoryUrl.snapRepositoryUrl)
} else {
uri(RepositoryUrl.repositoryUrl)
}
}
}
publications {
create<MavenPublication>("maven") {
artifactId = "interceptor"
from(components["java"])
}
}
}
}