Skip to content

Commit d4703dd

Browse files
committedJul 2, 2020
[Jetsnack] Update build to use spotless & buildSrc.
Change-Id: Ib7ec87d529c7309f3d21e41a0dc323b11b65c590
1 parent e4a85de commit d4703dd

File tree

9 files changed

+185
-58
lines changed

9 files changed

+185
-58
lines changed
 

‎Jetsnack/app/build.gradle

+21-38
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.example.jetsnack.buildsrc.Libs
18+
1719
plugins {
1820
id 'com.android.application'
1921
id 'kotlin-android'
2022
}
2123

2224
android {
23-
compileSdkVersion 29
25+
compileSdkVersion 30
2426

2527
defaultConfig {
2628
applicationId 'com.example.jetsnack'
2729
minSdkVersion 21
28-
targetSdkVersion 29
30+
targetSdkVersion 30
2931
versionCode 1
3032
versionName '1.0'
3133
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -43,52 +45,33 @@ android {
4345
targetCompatibility JavaVersion.VERSION_1_8
4446
}
4547

46-
kotlinOptions {
47-
jvmTarget = '1.8'
48-
apiVersion = '1.3'
49-
allWarningsAsErrors = true
50-
}
51-
5248
buildFeatures {
5349
compose true
50+
// Disable unused AGP features
51+
buildConfig false
52+
aidl false
53+
renderScript false
54+
resValues false
55+
shaders false
5456
}
5557

5658
composeOptions {
57-
kotlinCompilerVersion '1.3.70-dev-withExperimentalGoogleExtensions-20200424'
58-
kotlinCompilerExtensionVersion compose_version
59+
kotlinCompilerVersion Libs.AndroidX.Compose.kotlinCompilerVersion
60+
kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version
5961
}
6062
}
6163

62-
configurations {
63-
ktlint
64-
}
65-
6664
dependencies {
67-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
68-
implementation 'androidx.core:core-ktx:1.5.0-alpha01'
69-
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
70-
def coilVersion = "0.1.6.ui-$snapshot-SNAPSHOT"
71-
implementation "dev.chrisbanes.accompanist:accompanist-coil:$coilVersion"
72-
implementation "androidx.ui:ui-core:$compose_version"
73-
implementation "androidx.ui:ui-layout:$compose_version"
74-
implementation "androidx.ui:ui-material:$compose_version"
75-
implementation "androidx.ui:ui-material-icons-extended:$compose_version"
76-
implementation "androidx.ui:ui-tooling:$compose_version"
77-
ktlint "com.pinterest:ktlint:0.37.0"
78-
}
65+
implementation Libs.Kotlin.stdlib
7966

80-
task ktlint(type: JavaExec, group: "verification") {
81-
description = 'Check Kotlin code style.'
82-
main = 'com.pinterest.ktlint.Main'
83-
classpath = configurations.ktlint
84-
args 'src/**/*.kt'
85-
}
67+
implementation Libs.AndroidX.coreKtx
68+
implementation Libs.AndroidX.appcompat
8669

87-
check.dependsOn ktlint
70+
implementation Libs.AndroidX.UI.core
71+
implementation Libs.AndroidX.UI.layout
72+
implementation Libs.AndroidX.UI.material
73+
implementation Libs.AndroidX.UI.iconsExtended
74+
implementation Libs.AndroidX.UI.tooling
8875

89-
task ktlintFormat(type: JavaExec, group: 'formatting') {
90-
description = 'Fix Kotlin code style deviations.'
91-
main = 'com.pinterest.ktlint.Main'
92-
classpath = configurations.ktlint
93-
args '-F', 'src/**/*.kt'
76+
implementation Libs.Accompanist.coil
9477
}

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/utils/Insets.kt

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fun ProvideInsets(
5656
onCommit(setImmersiveFlags) {
5757
if (setImmersiveFlags) {
5858
// Set immersive flags to draw behind system bars
59+
@Suppress("DEPRECATION")
5960
view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
6061
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
6162
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

‎Jetsnack/app/src/main/java/com/example/jetsnack/ui/utils/SystemUi.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class SystemUiController(private val window: Window) {
5353
window.statusBarColor = statusBarColor.toArgb()
5454

5555
if (Build.VERSION.SDK_INT >= 23) {
56+
@Suppress("DEPRECATION")
5657
if (darkIcons) {
5758
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or
5859
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
@@ -88,6 +89,7 @@ class SystemUiController(private val window: Window) {
8889
window.navigationBarColor = navBarColor.toArgb()
8990

9091
if (Build.VERSION.SDK_INT >= 26) {
92+
@Suppress("DEPRECATION")
9193
if (darkIcons) {
9294
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or
9395
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
@@ -115,8 +117,8 @@ class SystemUiController(private val window: Window) {
115117
}
116118

117119
/**
118-
* An [Ambient] holding the current [SystemUiController] or throws an error if none is
119-
* [provided][androidx.compose.Providers].
120+
* An [androidx.compose.Ambient] holding the current [SystemUiController] or throws an error if none
121+
* is [provided][androidx.compose.Providers].
120122
*/
121123
val SystemUiControllerAmbient = staticAmbientOf<SystemUiController> {
122124
error("No SystemUiController provided")

‎Jetsnack/build.gradle

+29-9
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,52 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.example.jetsnack.buildsrc.Libs
18+
import com.example.jetsnack.buildsrc.Versions
19+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
20+
1721
buildscript {
18-
ext.kotlin_version = '1.3.72'
19-
ext.compose_version = '0.1.0-SNAPSHOT'
20-
ext.snapshot = '6581424'
2122
repositories {
2223
google()
2324
jcenter()
2425
}
2526
dependencies {
26-
classpath 'com.android.tools.build:gradle:4.2.0-alpha01'
27-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
27+
classpath Libs.androidGradlePlugin
28+
classpath Libs.Kotlin.gradlePlugin
2829
}
2930
}
3031

31-
allprojects {
32+
plugins {
33+
id 'com.diffplug.gradle.spotless' version '4.4.0'
34+
}
35+
36+
subprojects {
3237
repositories {
33-
maven { url "https://androidx.dev/snapshots/builds/$snapshot/artifacts/ui/repository" }
38+
maven { url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.UI.snapshot}/artifacts/ui/repository" }
3439
google()
3540
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
3641
jcenter()
3742
}
38-
// Don't require parens on fun type annotations e.g. `@Composable~()~ () -> Unit`. Remove with KT1.4
39-
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
43+
tasks.withType(KotlinCompile).all {
4044
kotlinOptions {
45+
jvmTarget = '1.8'
46+
apiVersion = '1.3'
47+
allWarningsAsErrors = true
48+
// Don't require parens on fun type annotations e.g. `@Composable~()~ () -> Unit`.
4149
freeCompilerArgs += '-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes'
50+
// Opt-in to experimental compose APIs
4251
freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
4352
}
4453
}
54+
apply plugin: 'com.diffplug.gradle.spotless'
55+
spotless {
56+
kotlin {
57+
target '**/*.kt'
58+
targetExclude("$buildDir/**/*.kt")
59+
targetExclude('bin/**/*.kt')
60+
61+
ktlint(Versions.ktlint)
62+
licenseHeaderFile rootProject.file('spotless/copyright.kt')
63+
}
64+
}
4565
}

‎Jetsnack/buildSrc/build.gradle.kts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
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+
repositories {
18+
jcenter()
19+
}
20+
21+
plugins {
22+
`kotlin-dsl`
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2020 The Android Open Source Project
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+
package com.example.jetsnack.buildsrc
18+
19+
object Versions {
20+
const val ktlint = "0.37.0"
21+
}
22+
23+
object Libs {
24+
const val androidGradlePlugin = "com.android.tools.build:gradle:4.2.0-alpha03"
25+
const val junit = "junit:junit:4.13"
26+
27+
object Accompanist {
28+
private const val version = "0.1.7.ui-${AndroidX.UI.snapshot}-SNAPSHOT"
29+
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
30+
}
31+
32+
object Kotlin {
33+
private const val version = "1.3.72"
34+
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version"
35+
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
36+
const val extensions = "org.jetbrains.kotlin:kotlin-android-extensions:$version"
37+
}
38+
39+
object Coroutines {
40+
private const val version = "1.3.7"
41+
const val core = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
42+
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
43+
const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$version"
44+
}
45+
46+
object AndroidX {
47+
const val appcompat = "androidx.appcompat:appcompat:1.3.0-alpha01"
48+
const val coreKtx = "androidx.core:core-ktx:1.5.0-alpha01"
49+
50+
object UI {
51+
const val snapshot = "6602655"
52+
const val version = "0.1.0-SNAPSHOT"
53+
54+
const val core = "androidx.ui:ui-core:$version"
55+
const val layout = "androidx.ui:ui-layout:$version"
56+
const val material = "androidx.ui:ui-material:$version"
57+
const val tooling = "androidx.ui:ui-tooling:$version"
58+
const val iconsExtended = "androidx.ui:ui-material-icons-extended:$version"
59+
}
60+
61+
object Compose {
62+
const val version = UI.version
63+
const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
64+
65+
const val runtime = "androidx.compose:compose-runtime:$version"
66+
}
67+
68+
object Test {
69+
private const val version = "1.2.0"
70+
const val core = "androidx.test:core:$version"
71+
const val rules = "androidx.test:rules:$version"
72+
73+
object Ext {
74+
private const val version = "1.1.2-rc01"
75+
const val junit = "androidx.test.ext:junit-ktx:$version"
76+
}
77+
78+
const val espressoCore = "androidx.test.espresso:espresso-core:3.2.0"
79+
}
80+
}
81+
}

‎Jetsnack/gradle.properties

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
# any settings specified in this file.
55
# For more details on how to configure your build environment visit
66
# http://www.gradle.org/docs/current/userguide/build_environment.html
7+
78
# Specifies the JVM arguments used for the daemon process.
89
# The setting is particularly useful for tweaking memory settings.
910
org.gradle.jvmargs=-Xmx2048m
10-
# When configured, Gradle will run in incubating parallel mode.
11-
# This option should only be used with decoupled projects. More details, visit
12-
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13-
# org.gradle.parallel=true
11+
12+
org.gradle.configureondemand=true
13+
org.gradle.caching=true
14+
org.gradle.parallel=true
15+
1416
# AndroidX package structure to make it clearer which packages are bundled with the
15-
# Android operating system, and which are packaged with your app"s APK
17+
# Android operating system, and which are packaged with your app's APK
1618
# https://developer.android.com/topic/libraries/support-library/androidx-rn
1719
android.useAndroidX=true
18-
# Automatically convert third-party libraries to use AndroidX
19-
android.enableJetifier=true
20+
2021
# Kotlin code style for this project: "official" or "obsolete":
21-
kotlin.code.style=official
22+
kotlin.code.style=official

‎Jetsnack/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-rc-1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip

‎Jetsnack/spotless/copyright.kt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright $YEAR The Android Open Source Project
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+

0 commit comments

Comments
 (0)
Please sign in to comment.