Skip to content

Commit

Permalink
docs: Update plugins features in README
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Jul 10, 2024
1 parent 937148a commit c5c9107
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 32 deletions.
129 changes: 106 additions & 23 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,7 +110,30 @@ android {

## Plugins

[![](https://mermaid.ink/img/eyJjb2RlIjoiZ3JhcGggQlRcbnN1YmdyYXBoIGluZnJhc3RydWN0dXJlLWFuZHJvaWRcbiAgICBhbmRyb2lkLWNvbmZpZ1tjb20ucmVkbWFkcm9ib3QuYW5kcm9pZC1jb25maWddXG4gICAgY29tLnJlZG1hZHJvYm90LmFwcGxpY2F0aW9uIC0tPiBhbmRyb2lkLWNvbmZpZ1xuICAgIGNvbS5yZWRtYWRyb2JvdC5hbmRyb2lkLWxpYnJhcnkgLS0-IGFuZHJvaWQtY29uZmlnXG5lbmRcblxuc3ViZ3JhcGggaW5mcmFzdHJ1Y3R1cmUtZGV0ZWt0XG4gICAgY29tLnJlZG1hZHJvYm90LmRldGVrdFxuZW5kXG5cbnN1YmdyYXBoIGluZnJhc3RydWN0dXJlLWtvdGxpblx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Y29uZmlnXG5lbmRcblxuc3ViZ3JhcGggaW5mcmFzdHJ1Y3R1cmUtcHVibGlzaFxuICAgIHB1Ymxpc2gtY29uZmlnW2NvbS5yZWRtYWRyb2JvdC5wdWJsaXNoLWNvbmZpZ11cbiAgICBjb20ucmVkbWFkcm9ib3QucHVibGlzaCAtLT4gcHVibGlzaC1jb25maWdcbmVuZFxuXG5hbmRyb2lkLWNvbmZpZyAtLT4ga290bGluLWNvbmZpZyIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOnRydWUsImF1dG9TeW5jIjp0cnVlLCJ1cGRhdGVEaWFncmFtIjp0cnVlfQ)
```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

Expand Down Expand Up @@ -221,22 +245,24 @@ publishing.publications.getByName<MavenPublication>(PUBLICATION_NAME) {

Common configurations for Android libraries and application.

Both:
[Both][BaseAndroidPlugin]:
- Specifies default compile, min and target SDK
- 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 `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
- Configures Android Lint [default options][lint-options]

#### QA build type name configuration

Expand Down Expand Up @@ -288,15 +314,68 @@ 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")

// 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 @@ -337,18 +416,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 @@ -495,7 +575,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 @@ -535,11 +615,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
4 changes: 2 additions & 2 deletions infrastructure-common/src/main/kotlin/StaticAnalyzerSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import org.gradle.api.file.DirectoryProperty
/** Options used for static analyzers' configurations. */
public interface StaticAnalyzerSpec {

/** Directory where stored configs for static analyzers. */
/** Directory with configs for static analyzers and other tools. */
public val configsDir: DirectoryProperty

/** Directory where will be stored static analyzers reports. */
/** Directory with reports of static analyzers and other tools. */
public val reportsDir: DirectoryProperty

public companion object {
Expand Down
9 changes: 6 additions & 3 deletions infrastructure-kotlin/src/main/kotlin/kotlin/TestOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions
/** Options used to configure tests. */
public interface TestOptions {

/** Flag for using Junit Jupiter Platform. Use functions [useJunit] or [useJunitPlatform]. */
/**
* Flag for using Junit Jupiter Platform.
* Use functions [useJunitPlatform] and [useJunit] to change it.
*/
public val useJunitPlatform: Provider<Boolean>

/** Specifies that JUnit Platform (JUnit 5) should be used to execute the tests. */
/** Specifies that JUnit Platform (JUnit 5) should be used to execute tests. */
public fun useJunitPlatform(configure: JUnitPlatformOptions.() -> Unit = {})

/** Specifies that JUnit should be used to execute the tests. */
/** Specifies that JUnit 4 should be used to execute tests. */
public fun useJunit(configure: JUnitOptions.() -> Unit = {})
}

0 comments on commit c5c9107

Please sign in to comment.