Skip to content

Commit 802dcf7

Browse files
committed
Create precompiled scripts convention plugins to be used as included builds
1 parent bd51b6c commit 802dcf7

8 files changed

+389
-0
lines changed

android/conventions/build.gradle.kts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
plugins {
17+
`kotlin-dsl`
18+
`kotlin-dsl-precompiled-script-plugins`
19+
}
20+
21+
repositories {
22+
google()
23+
mavenCentral()
24+
gradlePluginPortal()
25+
}
26+
27+
dependencies {
28+
// Workaround for using version catalog on precompiled scripts.
29+
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
30+
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
31+
implementation(gradleApi())
32+
implementation(libs.gradle.android.plugin)
33+
implementation(libs.gradle.kotlin.plugin)
34+
implementation(libs.gradle.errorprone.plugin)
35+
implementation(libs.gradle.nullaway.plugin)
36+
implementation(libs.gradle.spotless.plugin)
37+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
dependencyResolutionManagement {
17+
versionCatalogs {
18+
create("libs") {
19+
from(files("../gradle/libs.versions.toml"))
20+
}
21+
}
22+
}
23+
24+
rootProject.name = "conventions"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
import com.android.build.gradle.AbstractAppExtension
17+
import com.android.build.gradle.LibraryExtension
18+
import com.android.build.gradle.TestedExtension
19+
import com.android.build.gradle.api.BaseVariant
20+
import net.ltgt.gradle.errorprone.CheckSeverity
21+
import net.ltgt.gradle.errorprone.errorprone
22+
import net.ltgt.gradle.nullaway.nullaway
23+
24+
fun AbstractAppExtension.errorprone() {
25+
applicationVariants.configureEach { errorprone() }
26+
testErrorprone()
27+
}
28+
29+
fun LibraryExtension.errorprone() {
30+
libraryVariants.configureEach { errorprone() }
31+
testErrorprone()
32+
}
33+
34+
fun TestedExtension.testErrorprone() {
35+
testVariants.configureEach { errorprone() }
36+
unitTestVariants.configureEach { errorprone() }
37+
}
38+
39+
fun BaseVariant.errorprone() {
40+
javaCompileProvider.configure {
41+
options.errorprone.nullaway {
42+
severity.set(CheckSeverity.ERROR)
43+
annotatedPackages.add("com.uber")
44+
}
45+
options.errorprone.excludedPaths.set(".*/build/generated/.*")
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
@file:Suppress("UnstableApiUsage")
17+
18+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
19+
20+
plugins {
21+
kotlin("android")
22+
id("com.android.application")
23+
id("ribs.spotless-convention")
24+
}
25+
26+
kotlin {
27+
jvmToolchain(11)
28+
}
29+
30+
android {
31+
compileSdk = 33
32+
33+
defaultConfig {
34+
minSdk = 21
35+
targetSdk = 28
36+
versionCode = 1
37+
versionName = "1.0"
38+
}
39+
40+
compileOptions {
41+
sourceCompatibility = JavaVersion.VERSION_11
42+
targetCompatibility = JavaVersion.VERSION_11
43+
}
44+
45+
// No need for lint. Those are just tutorials.
46+
lint {
47+
abortOnError = false
48+
quiet = true
49+
}
50+
51+
buildTypes {
52+
debug {
53+
matchingFallbacks.add("release")
54+
}
55+
}
56+
57+
sourceSets {
58+
getByName("main").java.srcDir("src/main/kotlin")
59+
getByName("test").java.srcDir("src/test/kotlin")
60+
getByName("androidTest").java.srcDir("src/androidTest/kotlin")
61+
}
62+
}
63+
64+
androidComponents {
65+
beforeVariants { variantBuilder ->
66+
if (variantBuilder.buildType == "release") {
67+
variantBuilder.enable = false
68+
}
69+
}
70+
}
71+
72+
tasks.withType<KotlinCompile>().configureEach {
73+
compilerOptions {
74+
freeCompilerArgs.addAll(
75+
"-Xjvm-default=enable",
76+
"-opt-in=kotlin.RequiresOptIn",
77+
)
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
val libs = the<org.gradle.accessors.dm.LibrariesForLibs>()
17+
18+
plugins {
19+
id("ribs.kotlin-android-application-conventions")
20+
kotlin("kapt")
21+
id("net.ltgt.errorprone")
22+
id("net.ltgt.nullaway")
23+
id("ribs.spotless-convention")
24+
}
25+
26+
android {
27+
errorprone()
28+
}
29+
30+
dependencies {
31+
kapt(libs.autodispose.errorprone)
32+
kapt(libs.uber.nullaway)
33+
errorprone(libs.errorprone.core)
34+
errorprone(libs.guava.jre)
35+
errorproneJavac(libs.errorprone.javac)
36+
errorprone(libs.uber.nullaway)
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
@file:Suppress("UnstableApiUsage")
17+
18+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
19+
20+
plugins {
21+
kotlin("android")
22+
id("com.android.library")
23+
id("ribs.spotless-convention")
24+
}
25+
26+
kotlin {
27+
jvmToolchain(11)
28+
}
29+
30+
android {
31+
compileSdk = 33
32+
33+
defaultConfig {
34+
minSdk = 21
35+
}
36+
37+
// This can be removed on AGP 8.1.0-alpha09 onwards, since we are using JVM Toolchain
38+
compileOptions {
39+
sourceCompatibility = JavaVersion.VERSION_11
40+
targetCompatibility = JavaVersion.VERSION_11
41+
}
42+
43+
buildFeatures {
44+
buildConfig = false
45+
}
46+
47+
sourceSets {
48+
getByName("main").java.srcDir("src/main/kotlin")
49+
getByName("test").java.srcDir("src/test/kotlin")
50+
getByName("androidTest").java.srcDir("src/androidTest/kotlin")
51+
}
52+
53+
testOptions {
54+
unitTests {
55+
isIncludeAndroidResources = true
56+
}
57+
}
58+
}
59+
60+
androidComponents {
61+
beforeVariants { variantBuilder ->
62+
if (variantBuilder.buildType == "debug") {
63+
variantBuilder.enable = false
64+
}
65+
}
66+
}
67+
68+
tasks.withType<KotlinCompile>().configureEach {
69+
compilerOptions {
70+
freeCompilerArgs.addAll(
71+
"-Xexplicit-api=warning",
72+
"-Xjvm-default=enable",
73+
"-opt-in=kotlin.RequiresOptIn",
74+
)
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
plugins {
17+
kotlin("jvm")
18+
id("ribs.spotless-convention")
19+
}
20+
21+
kotlin {
22+
jvmToolchain(11)
23+
explicitApi()
24+
}
25+
26+
tasks.named("compileKotlin", org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask::class.java) {
27+
compilerOptions {
28+
freeCompilerArgs.add("-Xjvm-default=enable")
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2023. Uber Technologies
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+
* http://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+
plugins {
17+
id("com.diffplug.spotless")
18+
}
19+
20+
val libs = the<org.gradle.accessors.dm.LibrariesForLibs>()
21+
22+
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
23+
format("misc") {
24+
target("**/*.md", "**/.gitignore")
25+
trimTrailingWhitespace()
26+
endWithNewline()
27+
}
28+
kotlin {
29+
target("**/*.kt")
30+
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
31+
mapOf(
32+
"indent_size" to "2",
33+
"continuation_indent_size" to "4",
34+
)
35+
)
36+
ktfmt(libs.versions.ktfmt.get()).googleStyle()
37+
licenseHeaderFile(rootProject.file("config/spotless/copyright.kt"))
38+
trimTrailingWhitespace()
39+
endWithNewline()
40+
}
41+
java {
42+
target("src/*/java/**/*.java")
43+
googleJavaFormat(libs.versions.gjf.get())
44+
licenseHeaderFile(rootProject.file("config/spotless/copyright.java"))
45+
removeUnusedImports()
46+
trimTrailingWhitespace()
47+
endWithNewline()
48+
}
49+
kotlinGradle {
50+
target("**/*.gradle.kts")
51+
trimTrailingWhitespace()
52+
endWithNewline()
53+
}
54+
groovyGradle {
55+
target("**/*.gradle")
56+
trimTrailingWhitespace()
57+
endWithNewline()
58+
}
59+
}

0 commit comments

Comments
 (0)