Skip to content

Commit

Permalink
Migrate build scripts to kts, and version catalogs. (android#113)
Browse files Browse the repository at this point in the history
* Migrate build scripts to kts, and version catalogs.

* More migration to kts and version catalogs

* Added update deps workflow

* More migration to kts and version catalogs

* fix compose version

* Remove slices example

* Fix recomposehighlighter

* fix kotlin module

* Ignore tests that are meant to fail, and fix broken kotlin tests

* Disable bluetoothle building

* Load gradle plugins in top level build.gradle.kts, remove fileTree jar loading

* Add comma after last module name
  • Loading branch information
riggaroo authored Jun 20, 2023
1 parent e9e6e1f commit 26d153c
Show file tree
Hide file tree
Showing 51 changed files with 651 additions and 2,785 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: set up Java 11
- name: set up Java 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'zulu'
java-version: '17'
- name: Apply formatting if failed
run: ./gradlew :compose:spotlessApply --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply Spotless
- name: Build Compose
run: ./gradlew :compose:snippets:build
- name: Build recompose snippets
run: ./gradlew :compose:recomposehighlighter:build
- name: Build kotlin snippets
run: ./gradlew :kotlin:build
# TODO fix bluetoothle snippets (lint is failing) - name: Build bluetoothle snippets
# run: ./gradlew :bluetoothle:build

34 changes: 34 additions & 0 deletions .github/workflows/update_deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Update Versions / Dependencies

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
cache: gradle

- name: Update dependencies
run: ./gradlew versionCatalogUpdate
- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
commit-message: 🤖 Update Dependencies
committer: compose-devrel-github-bot <[email protected]>
author: compose-devrel-github-bot <[email protected]>
signoff: false
branch: bot-update-deps
delete-branch: true
title: '🤖 Update Dependencies'
body: Updated depedencies
35 changes: 0 additions & 35 deletions bluetoothle/build.gradle

This file was deleted.

44 changes: 44 additions & 0 deletions bluetoothle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}
android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "com.sample.android.bluetoothle"

defaultConfig {
applicationId = "com.sample.android.bluetoothle"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

buildTypes {
getByName("debug") {
signingConfig = signingConfigs.getByName("debug")
}

getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")
}
}
}
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.core)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.espresso.core)
}
2 changes: 1 addition & 1 deletion bluetoothle/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
2 changes: 2 additions & 0 deletions bluetoothle/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.android.bluetoothle">

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<application>
<activity android:name=".kotlin.MainActivity"></activity>
<activity android:name=".java.DeviceScanActivity" />
Expand Down
32 changes: 0 additions & 32 deletions build.gradle

This file was deleted.

13 changes: 13 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.gradle.versions)
alias(libs.plugins.version.catalog.update)
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kapt) apply false
alias(libs.plugins.hilt) apply false
}

apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")

45 changes: 45 additions & 0 deletions buildscripts/toml-updater-config.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
versionCatalogUpdate {
sortByKey.set(true)

keep {
// keep versions without any library or plugin reference
keepUnusedVersions.set(true)
// keep all libraries that aren't used in the project
keepUnusedLibraries.set(true)
// keep all plugins that aren't used in the project
keepUnusedPlugins.set(true)
}
}

def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}

tasks.named("dependencyUpdates").configure {
resolutionStrategy {
componentSelection {
all {
if (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) {
reject('Release candidate')
}
}
}
}
}
57 changes: 0 additions & 57 deletions compose/recomposehighlighter/build.gradle

This file was deleted.

61 changes: 61 additions & 0 deletions compose/recomposehighlighter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}
android {
compileSdk = libs.versions.compileSdk.get().toInt()
namespace = "com.example.recompose"

defaultConfig {
applicationId = "com.example.recompose"
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
getByName("debug") {
signingConfig = signingConfigs.getByName("debug")
}

getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
// Disable unused AGP features
viewBinding = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
}
dependencies {
val composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
androidTestImplementation(composeBom)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.foundation)
implementation(libs.androidx.compose.foundation.layout)
implementation(libs.androidx.compose.ui.util)
implementation(libs.androidx.compose.material)

implementation(libs.androidx.lifecycle.runtime)
testImplementation(libs.junit)
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.core)
androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.espresso.core)
}
5 changes: 2 additions & 3 deletions compose/recomposehighlighter/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.compose.recomposehighlighter">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:label="@string/app_name"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:name="com.example.android.compose.recomposehighlighter.MainActivity"
android:theme="@style/Theme.RecomposeHighlighter.NoActionBar"
android:exported="true">
<intent-filter>
Expand Down
5 changes: 2 additions & 3 deletions compose/recomposehighlighter/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.RecomposeHighlighter.NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<style name="Theme.RecomposeHighlighter.NoActionBar" parent="android:Theme.Material.Light.NoActionBar">

</style>
</resources>
Loading

0 comments on commit 26d153c

Please sign in to comment.