Skip to content

Commit 6dd49a5

Browse files
authored
chore: Migrate build logic to convention plugins (#60)
1 parent 3e69774 commit 6dd49a5

File tree

16 files changed

+551
-291
lines changed

16 files changed

+551
-291
lines changed

authenticator-screenshots/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16+
@Suppress("DSL_SCOPE_VIOLATION")
1617
plugins {
17-
id("com.android.library")
18-
id("org.jetbrains.kotlin.android")
19-
alias(dependency.plugins.paparazzi)
18+
id("amplify.android.library")
19+
alias(libs.plugins.paparazzi)
2020
}
2121

2222
android {
2323
namespace = "com.amplifyframework.ui.authenticator.screenshots"
2424
}
2525

2626
dependencies {
27-
implementation(dependency.bundles.compose)
28-
implementation(dependency.test.mockk)
27+
implementation(libs.bundles.compose)
28+
implementation(libs.test.mockk)
2929
implementation(projects.authenticator)
3030
}

authenticator/build.gradle.kts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
plugins {
2-
id("com.android.library")
3-
id("kotlin-android")
2+
id("amplify.android.ui.component")
43
}
5-
apply(from = rootProject.file("configuration/publishing.gradle"))
6-
7-
project.group = properties["POM_GROUP"].toString()
84

95
android {
106
namespace = "com.amplifyframework.ui.authenticator"
@@ -15,21 +11,15 @@ android {
1511
compileOptions {
1612
isCoreLibraryDesugaringEnabled = true
1713
}
18-
19-
publishing {
20-
singleVariant("release") {
21-
withSourcesJar()
22-
}
23-
}
2414
}
2515

2616
dependencies {
27-
api(dependency.amplify.auth)
17+
api(libs.amplify.auth)
2818

29-
implementation(dependency.bundles.compose)
30-
implementation(dependency.androidx.lifecycle)
31-
implementation(dependency.androidx.compose.viewmodel)
32-
coreLibraryDesugaring(dependency.android.desugar)
19+
implementation(libs.bundles.compose)
20+
implementation(libs.androidx.lifecycle)
21+
implementation(libs.androidx.compose.viewmodel)
22+
coreLibraryDesugaring(libs.android.desugar)
3323

3424
testImplementation(projects.testing)
3525
}

build-logic/plugins/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
@Suppress("DSL_SCOPE_VIOLATION")
17+
plugins {
18+
`kotlin-dsl`
19+
alias(libs.plugins.ktlint)
20+
}
21+
22+
java {
23+
sourceCompatibility = JavaVersion.VERSION_11
24+
targetCompatibility = JavaVersion.VERSION_11
25+
}
26+
27+
ktlint {
28+
android.set(true)
29+
}
30+
31+
dependencies {
32+
compileOnly(libs.plugin.android.gradle)
33+
compileOnly(libs.plugin.kotlin.gradle)
34+
compileOnly(libs.plugin.dokka)
35+
compileOnly(libs.plugin.ktlint)
36+
}
37+
38+
gradlePlugin {
39+
plugins {
40+
register("androidLibrary") {
41+
id = "amplify.android.library"
42+
implementationClass = "AndroidLibraryConventionPlugin"
43+
}
44+
register("publishing") {
45+
id = "amplify.android.publishing"
46+
implementationClass = "PublishingConventionPlugin"
47+
}
48+
register("dokka") {
49+
id = "amplify.android.dokka"
50+
implementationClass = "DokkaConventionPlugin"
51+
}
52+
register("ktlint") {
53+
id = "amplify.android.ktlint"
54+
implementationClass = "KtLintConventionPlugin"
55+
}
56+
register("component") {
57+
id = "amplify.android.ui.component"
58+
implementationClass = "ComponentConventionPlugin"
59+
}
60+
}
61+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import com.android.build.api.dsl.LibraryExtension
17+
import org.gradle.api.JavaVersion
18+
import org.gradle.api.Plugin
19+
import org.gradle.api.Project
20+
import org.gradle.api.tasks.compile.JavaCompile
21+
import org.gradle.api.tasks.testing.Test
22+
import org.gradle.kotlin.dsl.configure
23+
import org.gradle.kotlin.dsl.extra
24+
import org.gradle.kotlin.dsl.provideDelegate
25+
import org.gradle.kotlin.dsl.withType
26+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
27+
28+
val optInAnnotations = listOf(
29+
"com.amplifyframework.annotations.InternalApiWarning",
30+
"com.amplifyframework.annotations.InternalAmplifyApi"
31+
)
32+
33+
/**
34+
* This convention plugin configures an Android library module
35+
*/
36+
@Suppress("LocalVariableName")
37+
class AndroidLibraryConventionPlugin : Plugin<Project> {
38+
override fun apply(target: Project) {
39+
with(target.pluginManager) {
40+
apply("com.android.library")
41+
apply("org.jetbrains.kotlin.android")
42+
apply("amplify.android.ktlint")
43+
}
44+
45+
val POM_GROUP: String by target
46+
47+
with(target) {
48+
group = POM_GROUP
49+
extensions.configure<LibraryExtension> {
50+
configureAndroid(this)
51+
}
52+
53+
tasks.withType<JavaCompile>().configureEach {
54+
options.compilerArgs.apply {
55+
add("-Xlint:all")
56+
add("-Werror")
57+
}
58+
}
59+
60+
tasks.withType<Test>().configureEach {
61+
minHeapSize = "128m"
62+
maxHeapSize = "4g"
63+
}
64+
65+
tasks.withType<KotlinCompile> {
66+
compilerOptions {
67+
freeCompilerArgs.addAll(optInAnnotations.map { "-opt-in=$it" })
68+
}
69+
}
70+
}
71+
}
72+
73+
private fun Project.configureAndroid(extension: LibraryExtension) {
74+
val sdkVersionName = findProperty("VERSION_NAME") ?: rootProject.findProperty("VERSION_NAME")
75+
76+
if (hasProperty("signingKeyId")) {
77+
println("Getting signing info from protected source.")
78+
extra["signing.keyId"] = findProperty("signingKeyId")
79+
extra["signing.password"] = findProperty("signingPassword")
80+
extra["signing.inMemoryKey"] = findProperty("signingInMemoryKey")
81+
}
82+
83+
extension.apply {
84+
compileSdk = 33
85+
86+
defaultConfig {
87+
minSdk = 24
88+
targetSdk = 33
89+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
90+
testInstrumentationRunnerArguments += "clearPackageData" to "true"
91+
consumerProguardFiles += rootProject.file("configuration/consumer-rules.pro")
92+
93+
testOptions {
94+
animationsDisabled = true
95+
unitTests {
96+
isIncludeAndroidResources = true
97+
}
98+
}
99+
100+
buildConfigField("String", "VERSION_NAME", "\"$sdkVersionName\"")
101+
}
102+
103+
lint {
104+
warningsAsErrors = true
105+
abortOnError = true
106+
enable += listOf("UnusedResources", "NewerVersionAvailable")
107+
}
108+
109+
compileOptions {
110+
sourceCompatibility = JavaVersion.VERSION_1_8
111+
targetCompatibility = JavaVersion.VERSION_1_8
112+
}
113+
114+
// Needed when running integration tests. The oauth2 library uses relies on two
115+
// dependencies (Apache's httpcore and httpclient), both of which include
116+
// META-INF/DEPENDENCIES. Tried a couple other options to no avail.
117+
packagingOptions {
118+
resources.excludes.add("META-INF/DEPENDENCIES")
119+
}
120+
121+
buildFeatures {
122+
compose = true
123+
}
124+
125+
composeOptions {
126+
kotlinCompilerExtensionVersion = "1.4.3"
127+
}
128+
}
129+
}
130+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import org.gradle.api.Plugin
17+
import org.gradle.api.Project
18+
19+
/**
20+
* Shared plugin for UI component libraries
21+
*/
22+
class ComponentConventionPlugin : Plugin<Project> {
23+
override fun apply(target: Project) {
24+
with(target) {
25+
pluginManager.apply("amplify.android.library")
26+
pluginManager.apply("amplify.android.publishing")
27+
pluginManager.apply("amplify.android.dokka")
28+
}
29+
}
30+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
import org.gradle.kotlin.dsl.withType
4+
import org.jetbrains.dokka.DokkaDefaults.includeNonPublic
5+
import org.jetbrains.dokka.DokkaDefaults.jdkVersion
6+
import org.jetbrains.dokka.DokkaDefaults.reportUndocumented
7+
import org.jetbrains.dokka.DokkaDefaults.skipDeprecated
8+
import org.jetbrains.dokka.DokkaDefaults.skipEmptyPackages
9+
import org.jetbrains.dokka.gradle.DokkaTask
10+
11+
/*
12+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
13+
*
14+
* Licensed under the Apache License, Version 2.0 (the "License").
15+
* You may not use this file except in compliance with the License.
16+
* A copy of the License is located at
17+
*
18+
* http://aws.amazon.com/apache2.0
19+
*
20+
* or in the "license" file accompanying this file. This file is distributed
21+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
22+
* express or implied. See the License for the specific language governing
23+
* permissions and limitations under the License.
24+
*/
25+
26+
/**
27+
* Configures Dokka for API documentation
28+
*/
29+
class DokkaConventionPlugin : Plugin<Project> {
30+
override fun apply(target: Project) {
31+
with(target) {
32+
pluginManager.apply("org.jetbrains.dokka")
33+
tasks.withType<DokkaTask>().configureEach {
34+
dokkaSourceSets.configureEach {
35+
includeNonPublic.set(false)
36+
skipEmptyPackages.set(true)
37+
skipDeprecated.set(true)
38+
reportUndocumented.set(true)
39+
jdkVersion.set(8)
40+
}
41+
}
42+
}
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
/*
3+
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
import org.gradle.api.Plugin
18+
import org.gradle.api.Project
19+
import org.gradle.kotlin.dsl.configure
20+
import org.jlleitschuh.gradle.ktlint.KtlintExtension
21+
22+
/**
23+
* Applies and configures the KtLint plugin
24+
*/
25+
class KtLintConventionPlugin : Plugin<Project> {
26+
override fun apply(target: Project) {
27+
target.pluginManager.apply("org.jlleitschuh.gradle.ktlint")
28+
target.extensions.configure<KtlintExtension> {
29+
android.set(true)
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)