Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for release #140

Merged
merged 9 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

> [!NOTE]
> This release removes many implicit features that couldn't be configured from outside.
> It is also a part of a process of removing the features that could be easily implemented via [pre-compiled script plugins](https://docs.gradle.org/current/userguide/implementing_gradle_plugins_precompiled.html) (for example, SDK versions and tests configuration).
> It is recommended to migrate these configurations to pre-compiled script plugins.

### Stable `addSharedSourceSetRoot` extension

Experimental extension `addSharedSourceSetRoot(...)` has been replaced with the new stable version:
Expand All @@ -14,6 +19,19 @@ android {
}
```

### Introduce `SigningConfig.fromProperties` (Experimental)

It is common practice to store keystore credentials in `.properties` file.
This extension lets you apply configurations from a property file.

```kotlin
android {
signingConfigs.getByName<SigningConfig>("debug") {
fromProperties(file("cert/debug.properties"))
}
}
```

### :warning: BREAKING CHANGES

- **common:** Deprecate `redmadrobot.jvmTarget` with deprecation level `Error`.
Expand All @@ -26,23 +44,55 @@ android {
}
```
You can also configure [automatic toolchains downloading](https://docs.gradle.org/current/userguide/toolchains.html#sub:download_repositories).
- **android:** Don't set default `minSdk` (it was `23`) and `targetSdk` (it was `33`).
It was a poor decision to set defaults for these fields as could implicitly bump an SDK version in a project.
If you want to use `redmadrobot.android` to align SDK versions among all modules, you should set these properties explicitly:
```kotlin
redmadrobot {
android {
minSdk = 23
targetSdk = 34
}
}
```
- **common:** Disable [automatic repositories adding](https://github.com/RedMadRobot/gradle-infrastructure#automatically-added-repositories) by default.
If you rely on this feature, consider declaring required repositories explicitly, or enable it in `gradle.properties`:
```properties
redmadrobot.add.repositories=true
```
- **android:** Default `targetSdk` changed from `33` to `34`
- **android:** Don't apply [`org.gradle.android.cache-fix` plugin](https://github.com/gradle/android-cache-fix-gradle-plugin/) automatically.
This change allows removing android-cache-fix-gradle-plugin from the project dependencies.
See [the plugin documentation](https://github.com/gradle/android-cache-fix-gradle-plugin/?tab=readme-ov-file#applying-the-plugin) to learn how to apply this plugin to your project.
- **android:** Don't apply `proguard-android-optimize.txt` rules by default.
If you need these rules, apply it manually:
```kotlin
android {
defaultConfig {
proguardFile(getDefaultProguardFile("proguard-android-optimize.txt"))
}
}
```
- **android:** Do not add `LOCK_ORIENTATION` and `CRASH_REPORTS_ENABLED` variables to `BuildConfig` implicitly
- **kotlin:** Don't set `allWarningsAsErrors` flag implicitly.
It was impossible to disable this feature.
To keep going with the old behavior, add the following code to your build script:
```kotlin
val warningsAsErrors = findProperty("warningsAsErrors") == "true" || isRunningOnCi
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.allWarningsAsErrors = warningsAsErrors
}
```

### Other Changes

- **android:** Use `ANDROID_BUILD_TOOLS_VERSION` env variable for `buildToolsVersion` if the option is not configured (#132)
- **android:** Make an extension `Project.collectProguardFiles` public
- **android:** Add the option `redmadrobot.android.ndkVersion` to specify NDK version for all android modules
- **android:** Remove the workaround for Explicit API enabling as the issue has been [fixed](https://youtrack.jetbrains.com/issue/KT-37652) in Kotlin 1.9
- **android:** Remove disabling of build features `aidl`, `renderScript` and `buildConfig` as they are already disabled by default in new versions of AGP
- **kotlin:** Deprecate accessor `kotlinCompile`.
It is recommended to use `kotlin.compilerOptions { ... }` to configure compilation instead.
- Update Gradle to `8.8`
- Update Gradle to `8.9`

### Dependencies

Expand All @@ -56,8 +106,8 @@ infrastructure-kotlin:
- [Kotlin](https://kotlinlang.org/docs/whatsnew20.html) `1.8.10` → `2.0.0`

infrastructure-android:
- [Android Gradle Plugin](https://developer.android.com/studio/releases/gradle-plugin) `7.4.2` → `8.5.0`
- [Android cache fix Gradle plugin](https://github.com/gradle/android-cache-fix-gradle-plugin/releases/tag/v3.0.1) `2.7.0` → `3.0.1`
- [Android Gradle Plugin](https://developer.android.com/studio/releases/gradle-plugin) `7.4.2` → `8.5.1`
- Remove `android-cache-fix-gradle-plugin` from dependencies
- Remove `com.android.tools:common` from dependencies

infrastructure-detekt:
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,6 @@ dependencies {
}
```

### Warnings as errors

By default, infrastructure plugins enable Kotlin compiler's option `allWarningsAsErrors` (`-Werror`) on CI.
You can change it by defining the `warningsAsErrors` project property.

[Read more about Gradle project properties][project-properties]

### Share sources between build variants

You can share sources between two build variants.
Expand Down
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ infrastructure = "0.18.1"
infrastructure-kotlin = { module = "com.redmadrobot.build:infrastructure-kotlin", version.ref = "infrastructure" }
infrastructure-detekt = { module = "com.redmadrobot.build:infrastructure-detekt", version.ref = "infrastructure" }
infrastructure-publish = { module = "com.redmadrobot.build:infrastructure-publish", version.ref = "infrastructure" }
androidTools-gradle = "com.android.tools.build:gradle:8.5.0"
androidGradleCacheFix = "gradle.plugin.org.gradle.android:android-cache-fix-gradle-plugin:3.0.1"
androidTools-gradle = "com.android.tools.build:gradle:8.5.1"
detektGradle = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.6"
kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0"
pluginPublish = "com.gradle.publish:plugin-publish-plugin:1.2.1"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 4 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
4 changes: 1 addition & 3 deletions infrastructure-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,5 @@ gradlePlugin {
dependencies {
api(projects.infrastructureKotlin)

compileOnly(libs.androidTools.gradle) // Should be provided by project

implementation(libs.androidGradleCacheFix)
compileOnly(libs.androidTools.gradle) // Should be provided by a project
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.android.build.api.variant.ApplicationVariant
import com.redmadrobot.build.StaticAnalyzerSpec
import com.redmadrobot.build.android.internal.android
import com.redmadrobot.build.android.internal.androidComponents
import com.redmadrobot.build.android.internal.projectProguardFiles
import com.redmadrobot.build.android.internal.ifPresent
import com.redmadrobot.build.android.task.MakeDebuggableTask
import com.redmadrobot.build.dsl.*
import org.gradle.api.Project
Expand All @@ -36,7 +36,7 @@ public class AndroidApplicationPlugin : BaseAndroidPlugin("com.android.applicati
private fun Project.configureApp() = android<ApplicationExtension> {
defaultConfig {
// Collect proguard rules from 'proguard' dir
setProguardFiles(projectProguardFiles() + getDefaultProguardFile("proguard-android-optimize.txt"))
proguardFiles.addAll(collectProguardFiles())
}

finalizeQaBuildType()
Expand Down Expand Up @@ -83,9 +83,7 @@ private fun ApplicationExtension.finalizeApp(
androidOptions: AndroidOptions,
staticAnalyzerSpec: StaticAnalyzerSpec,
) {
defaultConfig {
targetSdk = androidOptions.targetSdk.get()
}
androidOptions.targetSdk.ifPresent { defaultConfig.targetSdk = it }

lint {
xmlOutput = staticAnalyzerSpec.reportsDir.file("lint-results.xml").get().asFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.redmadrobot.build.android

import com.android.build.api.dsl.LibraryExtension
import com.redmadrobot.build.android.internal.android
import com.redmadrobot.build.android.internal.projectProguardFiles
import com.redmadrobot.build.dsl.collectProguardFiles
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension

Expand All @@ -20,7 +20,7 @@ public class AndroidLibraryPlugin : BaseAndroidPlugin("com.android.library") {
android<LibraryExtension> {
defaultConfig {
// Add all files from 'proguard' dir
consumerProguardFiles.addAll(projectProguardFiles())
consumerProguardFiles.addAll(collectProguardFiles())
}

buildFeatures {
Expand Down
15 changes: 3 additions & 12 deletions infrastructure-android/src/main/kotlin/android/AndroidOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ import org.gradle.api.tasks.TaskProvider
/** Options for android projects. */
public interface AndroidOptions {

/**
* Minimal Android SDK to be used in all android modules.
* By default, SDK 23 is used.
*/
/** Minimal Android SDK to be used in all android modules. */
public val minSdk: Property<Int>

/**
* Target Android SDK to be used in all android modules.
* By default, SDK 34 is used.
*/
/** Target Android SDK to be used in all android modules. */
public val targetSdk: Property<Int>

/**
Expand Down Expand Up @@ -48,8 +42,5 @@ public interface AndroidOptions {
*/
public val testTasksFilter: Property<(TaskProvider<*>) -> Boolean>

public companion object {
internal const val DEFAULT_MIN_API = 23
internal const val DEFAULT_TARGET_API = 34
}
public companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ internal abstract class AndroidOptionsImpl @Inject constructor(

init {
minSdk
.convention(AndroidOptions.DEFAULT_MIN_API)
.finalizeValueOnRead()
targetSdk
.convention(AndroidOptions.DEFAULT_TARGET_API)
.finalizeValueOnRead()
compileSdk
.convention(targetSdk.map(Int::toString))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.redmadrobot.build.StaticAnalyzerSpec
import com.redmadrobot.build.android.internal.*
import com.redmadrobot.build.internal.InternalGradleInfrastructureApi
import com.redmadrobot.build.internal.addRepositoriesIfNeed
import com.redmadrobot.build.kotlin.internal.configureKotlin
import com.redmadrobot.build.kotlin.internal.setTestOptions
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -32,18 +31,12 @@ public abstract class BaseAndroidPlugin internal constructor(

internal abstract fun Project.configure(configPlugin: AndroidConfigPlugin)

@OptIn(InternalGradleInfrastructureApi::class)
private fun Project.applyBaseAndroidPlugin(pluginId: String, configPlugin: AndroidConfigPlugin) {
apply {
plugin(pluginId)
plugin("kotlin-android")

// Apply fix for Android caching problems
// See https://github.com/gradle/android-cache-fix-gradle-plugin
plugin("org.gradle.android.cache-fix")
}

configureKotlin()
configureAndroid()
androidComponents {
finalizeDsl { extension ->
Expand Down Expand Up @@ -76,13 +69,10 @@ private fun CommonExtension.applyAndroidOptions(
options: AndroidOptions,
staticAnalyzerSpec: StaticAnalyzerSpec,
) {
setCompileSdkVersion(options.compileSdk.get())
options.compileSdk.ifPresent { setCompileSdkVersion(it) }
options.buildToolsVersion.ifPresent { buildToolsVersion = it }
options.ndkVersion.ifPresent { ndkVersion = it }

defaultConfig {
minSdk = options.minSdk.get()
}
options.minSdk.ifPresent { defaultConfig.minSdk = it }

testOptions {
unitTests.all { it.setTestOptions(options.test) }
Expand All @@ -94,7 +84,7 @@ private fun CommonExtension.applyAndroidOptions(
}
}

/** Universal function to set compile SDK even if it is preview version. */
/** Universal function to set compile SDK even if it is a preview version. */
private fun CommonExtension.setCompileSdkVersion(version: String) {
val intVersion = version.toIntOrNull()
if (intVersion != null) {
Expand All @@ -104,7 +94,7 @@ private fun CommonExtension.setCompileSdkVersion(version: String) {
}
}

/** Filter unit tests to be run with 'test' task. */
/** Filter unit tests to be run with the 'test' task. */
private fun Project.filterTestTaskDependencies(options: AndroidOptions) {
afterEvaluate {
tasks.named("test") {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.redmadrobot.build.android.internal

import org.gradle.api.provider.Property

internal fun <T> Property<T>.ifPresent(action: (T) -> Unit) {
internal inline fun <T> Property<T>.ifPresent(action: (T) -> Unit) {
if (isPresent) action(get())
}
11 changes: 11 additions & 0 deletions infrastructure-android/src/main/kotlin/dsl/ProjectProguardFiles.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.redmadrobot.build.dsl

import org.gradle.api.Project
import java.io.File

/** Collects proguard rules from the specified [path]. */
public fun Project.collectProguardFiles(path: String = "proguard"): List<File> {
return fileTree(path)
.files
.filter { it.extension == "pro" }
}
29 changes: 29 additions & 0 deletions infrastructure-android/src/main/kotlin/dsl/Signing.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package dsl

import com.android.build.api.dsl.SigningConfig
import org.gradle.api.Incubating
import java.io.File
import java.util.*

/**
* Applies signature configuration from the specified [propertiesFile].
*
* The file content should have the following format:
* ```
* store_file=[relative path to keystore file]
* store_password=[keystore password]
* key_alias=[the alias of the needed key]
* key_password=[the password for the specified alias]
* ```
*/
@Incubating
public fun SigningConfig.fromProperties(propertiesFile: File) {
val directory = propertiesFile.parentFile
val properties = Properties()
propertiesFile.inputStream().use(properties::load)

storeFile = File(directory, properties.getProperty("store_file"))
storePassword = properties.getProperty("store_password")
keyAlias = properties.getProperty("key_alias")
keyPassword = properties.getProperty("key_password")
}
2 changes: 1 addition & 1 deletion infrastructure-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ gradlePlugin {

dependencies {
api(projects.infrastructureCommon)
compileOnlyApi(libs.kotlinGradle) // Should be provided by project
compileOnlyApi(libs.kotlinGradle) // Should be provided by a project
}
Loading