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

Cleaning #138

Merged
merged 10 commits into from
Jul 17, 2024
15 changes: 10 additions & 5 deletions .idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,30 @@ android {

### :warning: BREAKING CHANGES

- **common:** Deprecate `redmadrobot.jvmTarget` with deprecation level `Error`.
Use [JVM Toolchains](https://kotl.in/gradle/jvm/toolchain) instead to specify JVM target.
Kotlin, Android Gradle Plugin, detekt and many other tools have support for this mechanism,
In most cases, adding this into your `build.gradle.kts` should be enough:
```kotlin
kotlin {
jvmToolchain(17)
}
```
You can also configure [automatic toolchains downloading](https://docs.gradle.org/current/userguide/toolchains.html#sub:download_repositories).
- **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:** Do not add `LOCK_ORIENTATION` and `CRASH_REPORTS_ENABLED` variables to `BuildConfig` implicitly

### Other Changes

- **android:** Use `ANDROID_BUILD_TOOLS_VERSION` env variable for `buildToolsVersion` if the option is not configured (#132)
- **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`
Expand Down
152 changes: 118 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

Small plugins to reduce boilerplate in Gradle build scripts.

> :warning: It is designed to use with Gradle Kotlin DSL and can't be used from Groovy DSL.
> [!IMPORTANT]
> These plugins are designed to be used with Gradle Kotlin DSL only.

---
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
Expand All @@ -24,7 +25,7 @@ Small plugins to reduce boilerplate in Gradle build scripts.
- [Configuration](#configuration)
- [Align version of all Kotlin libraries](#align-version-of-all-kotlin-libraries)
- [Warnings as errors](#warnings-as-errors)
- [Share sources between build types](#share-sources-between-build-types)
- [Share sources between build variants](#share-sources-between-build-variants)
- [Enable Detekt checks only on changed files](#enable-detekt-checks-only-on-changed-files)
- [Configure JUnit test execution options](#configure-junit-test-execution-options)
- [Automatically added repositories](#automatically-added-repositories)
Expand Down Expand Up @@ -109,15 +110,36 @@ android {

## Plugins

[![](https://mermaid.ink/img/eyJjb2RlIjoiZ3JhcGggQlRcbnN1YmdyYXBoIGluZnJhc3RydWN0dXJlLWFuZHJvaWRcbiAgICBhbmRyb2lkLWNvbmZpZ1tjb20ucmVkbWFkcm9ib3QuYW5kcm9pZC1jb25maWddXG4gICAgY29tLnJlZG1hZHJvYm90LmFwcGxpY2F0aW9uIC0tPiBhbmRyb2lkLWNvbmZpZ1xuICAgIGNvbS5yZWRtYWRyb2JvdC5hbmRyb2lkLWxpYnJhcnkgLS0-IGFuZHJvaWQtY29uZmlnXG5lbmRcblxuc3ViZ3JhcGggaW5mcmFzdHJ1Y3R1cmUtZGV0ZWt0XG4gICAgY29tLnJlZG1hZHJvYm90LmRldGVrdFxuZW5kXG5cbnN1YmdyYXBoIGluZnJhc3RydWN0dXJlLWtvdGxpblxuICAgIGtvdGxpbi1jb25maWdbY29tLnJlZG1hZHJvYm90LmtvdGxpbi1jb25maWddXG4gICAgY29tLnJlZG1hZHJ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tY29uZmlnW2NvbS5yZWRtYWRyb2JvdC5wdWJsaXNoLWNvbmZpZ11cbiAgICBjb20ucmVkbWFkcm9ib3QucHVibGlzaCAtLT4gcHVibGlzaC1jb25maWdcbmVuZFxuXG5hbmRyb2lkLWNvbmZpZyAtLT4ga290bGluLWNvbmZpZyIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOnRydWUsImF1dG9TeW5jIjp0cnVlLCJ1cGRhdGVEaWFncmFtIjp0cnVlfQ)
```mermaid
graph BT
subgraph infrastructure-android
android-config[com.redmadrobot.android-config]
com.redmadrobot.application --> android-config
com.redmadrobot.android-library --> android-config
end

subgraph infrastructure-detekt
com.redmadrobot.detekt
end

subgraph infrastructure-kotlin
kotlin-config[com.redmadrobot.kotlin-config]
com.redmadrobot.kotlin-library --> kotlin-config
end

subgraph infrastructure-publish
publish-config[com.redmadrobot.publish-config]
com.redmadrobot.publish --> publish-config
end

android-config --> kotlin-config
```

### kotlin-library

Common configurations for pure Kotlin libraries.

- Applies plugin `kotlin`
- Specifies `jvmTarget` 11
- Adds repository `mavenCentral` (see [Automatically added repositories](#automatically-added-repositories))
- Enables [explicit API mode][explicit-api]

### publish
Expand Down Expand Up @@ -206,7 +228,6 @@ publishing.publications.getByName<MavenPublication>(PUBLICATION_NAME) {

### detekt

- Adds repository `mavenCentral` (see [Automatically added repositories](#automatically-added-repositories))
- Applies `detekt` plugin with `detekt-formatting`
- Configures additional tasks:
- `detektAll` - Runs Detekt over the whole codebase
Expand All @@ -224,25 +245,24 @@ publishing.publications.getByName<MavenPublication>(PUBLICATION_NAME) {

Common configurations for Android libraries and application.

Both:
- Specifies `jvmTarget` and `compatibility` 11
[Both][BaseAndroidPlugin]:
- Specifies default compile, min and target SDK
- Disables `aidl`, `renderScript` and `shaders` [build-features]
- Adds repositories `mavenCentral` and `google` (see [Automatically added repositories](#automatically-added-repositories))
- Disables `shaders` [build-features] by default
- Applies [android-cache-fix-gradle-plugin](https://github.com/gradle/android-cache-fix-gradle-plugin)
- Configures Android Lint with [defaults][lint-options]
- [Filters tests][testTaskFilter] to be run on `test` task according to the config.
By default, keeps only tests for build type `release`.

Library:
[Library][AndroidLibraryPlugin]:
- Applies plugin `com.android.library`
- Adds all proguard files from `proguard` folder as `consumerProguardFiles`
- Disables `buildConfig`, `androidResources` and `resValues` [build-features]
- Disables `androidResources` and `resValues` [build-features] by default
- Enables [explicit API mode][explicit-api]

Application:
[Application][AndroidApplicationPlugin]:
- Applies plugin `com.android.application`
- Adds all proguard files from `proguard` folder
- Configures `debug`, `qa` and `release` build types
- Adds `LOCK_ORIENTATION` and `CRASH_REPORTS_ENABLED` BuildConfig variables which `false` only for `debug` build type
- Configures Android Lint [default options][lint-options]

#### QA build type name configuration

Expand Down Expand Up @@ -294,15 +314,71 @@ See [compatibility table](#compatibility) to check what versions are compatible

### Configuration

You can configure the plugins with an extension named `redmadrobot`.
Look for available properties with description in [RedmadrobotExtension].
You can configure the plugins via the `redmadrobot` extension.
Here are listed all available options, with their default values:

The extension should be configured in root project.
```kotlin
// root project build.gradle.kts

redmadrobot {
configsDir = file("path/to/configs/")
/* Common options */
// Directory with configs for static analyzers and other tools.
configsDir = file("config/")

// Directory with reports of static analyzers and other tools.
reportsDir = file("build/reports/")

/* `kotlin-config` options */
test {
// Specifies that JUnit Platform (JUnit 5) should be used to execute tests.
useJunitPlatform()

// Specifies that JUnit 4 should be used to execute tests.
useJunit()
}

/* `android-config` options */
android {
// minSdk to be used in all android modules.
minSdk = 23

// targetSdk to be used in all android modules.
targetSdk = 34

// compileSdk to be used in all android modules
compileSdk = "34"

// Build Tools version to be used in all android modules.
buildToolsVersion = System.getenv("ANDROID_BUILD_TOOLS_VERSION")

// NDK version to be used in all android modules.
ndkVersion = System.getenv("ANDROID_NDK_VERSION")

// Filter for test tasks that should be run on ':test'.
testTasksFilter = { taskProvider -> taskProvider.name.endsWith("ReleaseUnitTest") }

// Overrides of test configuration for android projects
test { /* ... */ }
}

/* `detekt` options */
detekt {
// Enable Detekt checks only for modified files
// (Disabled by default)
checkOnlyDiffWithBranch(branch = "main") {
fileExtensions = setOf(".kt", ".kts")
}
}

/* `publish-config` options */
publishing {
// Enables artifacts signing before publication.
signArtifacts = false

// Use gpg-agent to sign artifacts. Has effect only if signArtifacts is `true`.
useGpgAgent = true

// Configures POM file for this project and its subprojects.
pom { /* ... */ }
}
}
```

Expand Down Expand Up @@ -343,18 +419,19 @@ You can change it by defining the `warningsAsErrors` project property.

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

### Share sources between build types
### Share sources between build variants

You can share sources between two build variants.
For example, you need to use debug panel in both "debug" and "QA" builds, and don't want to duplicate code for each of these build types.
You can do it in one line with [addSharedSourceSetRoot] extension-function:

You can share sources between two build types.
For example, you need to use debug panel in both debug and QA builds, and don't want to write similar duplicating code for each of these build types.
You can do it with one line with [addSharedSourceSetRoot] extension-function:
```kotlin
android {
// We need to share sources between debug and QA builds
addSharedSourceSetRoot(BUILD_TYPE_DEBUG, BUILD_TYPE_QA)
sourceSet.addSharedSourceSetRoot(BUILD_TYPE_DEBUG, BUILD_TYPE_QA)

// We can specify name for the source set root if need
addSharedSourceSetRoot(BUILD_TYPE_DEBUG, BUILD_TYPE_QA, name = "debugPanel")
// We can specify a name for the source set root if needed
sourceSet.addSharedSourceSetRoot(BUILD_TYPE_DEBUG, BUILD_TYPE_QA, name = "debugPanel")
}
```

Expand Down Expand Up @@ -424,16 +501,20 @@ redmadrobot {

### Automatically added repositories

Infrastructure plugins automatically add repositories required to make project work:
> [!WARNING]
> This feature is deprecated and is disabled by default since v0.19
> Currently you can enable this behavior, though this option may be deleted at some point.

Infrastructure plugins can automatically add required repositories:

- **kotlin** plugin adds `mavenCentral` repo
- **detekt** plugin adds `mavenCentral` repo
- **android** plugins add `mavenCentral` and `google` repos

In the case you don't want these repositories to be added automatically, you can disable this behavior via flag in `gradle.properties`:
This feature should be enabled by flag in `gradle.properties`:

```properties
redmadrobot.add.repositories=false
redmadrobot.add.repositories=true
```

## Samples
Expand Down Expand Up @@ -497,7 +578,7 @@ Execution failed for task ':app:stripDebugDebugSymbols'.
It is because NDK version on CI differs from a requested version.
You can change requested version by setting `android.ndkVersion`.

Plugins `com.redmadrobot.android-library` and `com.redmadrobot.application` by default apply NDK version from env variable `ANDROID_NDK_VERSION` if it set.
Plugins `com.redmadrobot.android-library` and `com.redmadrobot.application` by default apply NDK version from env variable `ANDROID_NDK_VERSION` if it is set.

### `Could not resolve` or `Could not find` dependencies

Expand Down Expand Up @@ -537,11 +618,14 @@ For major changes, please open an issue first to discuss what you would like to
[MIT][license]

[samples]: samples/
[RedmadrobotExtension]: infrastructure/src/main/kotlin/extension/RedmadrobotExtension.kt
[MavenPom]: infrastructure/src/main/kotlin/dsl/MavenPom.kt
[predicates]: infrastructure/src/main/kotlin/dsl/PublishingPredicates.kt
[addSharedSourceSetRoot]: infrastructure-android/src/main/kotlin/dsl/SourceSets.kt
[lint-options]: https://github.com/RedMadRobot/gradle-infrastructure/blob/2e96c04cbb9d15ca508d1d4b4a8b1e2da4bab6af/infrastructure/src/main/kotlin/AndroidApplicationPlugin.kt#L63-L72
[lint-options]: infrastructure-android/src/main/kotlin/android/BaseAndroidPlugin.kt#L76-L80
[testTaskFilter]: infrastructure-android/src/main/kotlin/android/AndroidOptions.kt#L28-L35
[BaseAndroidPlugin]: infrastructure-android/src/main/kotlin/android/BaseAndroidPlugin.kt
[AndroidLibraryPlugin]: infrastructure-android/src/main/kotlin/android/AndroidLibraryPlugin.kt
[AndroidApplicationPlugin]: infrastructure-android/src/main/kotlin/android/AndroidApplicationPlugin.kt

[infrastructure]: #
[itemsadapter]: https://github.com/RedMadRobot/itemsadapter
Expand Down
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import com.redmadrobot.build.dsl.developer
import com.redmadrobot.build.dsl.isRunningOnCi
import com.redmadrobot.build.dsl.mit
import com.redmadrobot.build.dsl.setGitHubProject
import com.redmadrobot.build.dsl.*

plugins {
id("com.redmadrobot.detekt")
Expand Down
Loading