protoncore_android/plugins
Marino Meneghel aa6292cc3f fix: Avoid build failures when running core as a local build
When running mail project including core as a local build
(by enabling `local.git.proton-libs=../proton-libs` in gradle.properties)
the build fails as it can't resolve what `extensions` is.
Casting BaseFlavor extension to ExtensionAware explicitly solves this.
2024-04-04 10:58:06 +02:00
..
core feat(user-recovery): Added User Recovery modules. 2024-04-02 16:15:03 +02:00
coverage chore: Upgraded Kotlin to 1.9.22 (and needed dependencies). 2024-02-28 18:09:18 +00:00
detekt chore: Upgraded Kotlin to 1.9.22 (and needed dependencies). 2024-02-28 18:09:18 +00:00
environment-configuration fix: Avoid build failures when running core as a local build 2024-04-04 10:58:06 +02:00
gradle/wrapper chore: Upgraded Kotlin to 1.9.22 (and needed dependencies). 2024-02-28 18:09:18 +00:00
include-core-build chore(include-core-build): Added Gitlab Job Token support. 2022-11-21 13:26:20 +01:00
jacoco chore: Upgraded Kotlin to 1.9.22 (and needed dependencies). 2024-02-28 18:09:18 +00:00
publish-core-libraries build: Update publishing plugins. 2024-02-08 18:44:05 +01:00
publish-core-plugins chore: Upgraded Gradle to 8.0.2. 2023-07-03 18:27:27 +02:00
shared/src/main/kotlin build: Fix configuration cache problems. 2023-11-17 13:38:22 +00:00
tests build: Migrate away from deprecated APIs. 2023-11-17 13:38:22 +00:00
.gitignore
CHANGELOG.md docs: Updated Changelog for Proton Gradle Plugins version 1.3.1. 2024-03-26 15:37:08 +01:00
README.md chore: Added environment config gradle plugin 2023-09-14 08:29:57 +00:00
build.gradle.kts
gradle.properties Eanble gradle caching and parallel flags for plugins project 2021-12-14 11:26:43 +01:00
gradlew chore: Upgraded Kotlin to 1.9.22 (and needed dependencies). 2024-02-28 18:09:18 +00:00
gradlew.bat build: Build tools update. 2023-11-17 13:38:22 +00:00
settings.gradle.kts chore: Added environment config gradle plugin 2023-09-14 08:29:57 +00:00

README.md

This project contains several gradle plugins. These plugins are used by the core project or can be used by other project as some are published on MavenCentral.

Setup

Kotlin Gradle DSL using detekt plugin:

settings.gradle.kts

pluginManagement {
    repositories {
        mavenCentral() // for stable release
    }
}
build.gradle.kts

plugins {
    id("me.proton.core.gradle-plugins.detekt") version "plugin-version"
}

More info about setup, like groovy variant or legacy setup can be found at https://docs.gradle.org/current/userguide/plugins.html.

Plugins

Core plugins

  • Plugins can be applied via extension functions (inside the plugins block): protonAndroidLibrary, protonAndroidUiLibrary, protonComposeUiLibrary, protonDagger , protonKotlinLibrary
  • Not published on MavenCentral.

Use internally in core project to orchestrate dependencies and apply android/kotlin/dagger convention config.

Coverage plugin

  • Plugin id: me.proton.core.gradle-plugins.coverage
  • Published on MavenCentral.

Apply the plugin to each (non-root) project for which the code coverage is needed. Additional settings can be configured via protonCoverage extension, e.g. setting custom minimum coverage levels, excluding additional files.

Global coverage plugin

  • Plugin id: me.proton.core.gradle-plugins.global-coverage
  • Published on MavenCentral.

The plugin is intended to be applied to a separate project, that's only used to generate a global coverage report or perform coverage percentage verification.

Common coverage config plugin

  • Plugin id: me.proton.core.gradle-plugins.coverage-config
  • Published on MavenCentral.

Apply the plugin on the root project. Use the protonCoverage extension to configure common coverage settings. Those settings will be picked up the all the submodules that use the Coverage plugin (me.proton.core.gradle-plugins.coverage).

Detekt plugin

  • Plugin id: me.proton.core.gradle-plugins.detekt
  • Published on MavenCentral.

This plugin should be applied to the root build.gradle file. It adds a multiModuleDetekt task which generate GitLab CI compatible report.

You can setup the following stage in your .gitlab-ci:

detekt analysis:
  script:
    - ./gradlew multiModuleDetekt
  artifacts:
    reports:
      codequality: config/detekt/reports/mergedReport.json

Jacoco plugin

  • Plugin id: me.proton.core.gradle-plugins.jacoco
  • Published on MavenCentral.

This plugin should be applied to the root build.gradle file. It adds a coberturaCoverageReport task which generate GitLab CI compatible report.

coverage report:
  script:
    - ./gradlew -Pci --console=plain coberturaCoverageReport # This also runs allTest
  coverage: /Total.*?(\d{1,3}\.\d{0,2})%/
  artifacts:
    expire_in: 1 week
    paths:
      - ./build/reports/*
    reports:
      cobertura:
        - ./build/reports/cobertura-coverage.xml

It also allows for further customization. See the plugin's README for more info.

Include Core Build plugin

  • Plugin id: me.proton.core.gradle-plugins.include-core-build
  • Published on MavenCentral.

Gradle Settings Plugin to automatically checkout the Proton Core Build, if needed.

settings.gradle.kts

plugins {
  id("me.proton.core.gradle-plugins.include-core-build") version "plugin-version"
}

Git Repo Uri:

Git Clone/Checkout/IncludeBuild:

  • if env CORE_COMMIT_SHA exist -> clone/checkout and include full build from provided commit sha, in parent directory.
  • if config has includes (see below) -> clone/checkout and include only included projects from provided branch, tag or commit, in parent directory.

Configuration:

settings.gradle.kts

plugins {
  id("me.proton.core.gradle-plugins.include-core-build") version "plugin-version"
}

includeCoreBuild {
  // refreshIntervalMillis.set("86400000") // How often the repository should be updated, default 24h.
  branch.set("main")
  // tag.set("1.0.0")
  // commit.set("commitSha")
  includeBuild("gopenpgp") // Checkout "proton-libs" in parent dir and include "gopenpgp" build.
}

Override include with local:

gradle.properties

local.git.proton-libs=../proton-libs

Note: This plugin in based on IncludeGit Gradle Plugin.

Publish-core-libraries plugin

  • Plugin id: publish-core-libraries
  • Not published on MavenCentral.

Use internally in core project to orchestrate core libraries publication.

Environment configuration plugin

  • Plugin id: me.proton.core.gradle-plugins.environment-config
  • Published on MavenCentral.

This plugin should be applied to either build flavor or application build type android extension in build.gradle.kts file.

Generates build/generated/source/envConfig/{flavor}/{buildType}/EnvironmentConfigurationDefaults.java similarly to BuildConfig.java. Generated class is then added to source directories and can be accessed at runtime

  • Automatically obtains and sets proxy token if useProxy is set to true
  • By default (if no configuration provided in build.gradle.kts) generates a default production config (api.proton.me)
build.gradle.kts

plugins {
    id("me.proton.core.gradle-plugins.environment-config")
}

android {
    buildTypes {
        debug {
            environmentConfig {
                useProxy = true // use proxy on all debug builds. Defaults to 'false'
            }
        }
    }

    defaultConfig {
        environmentConfig {
            apiPrefix = "mail-api" // will result in base url https://mail-api.proton.me
        }
    }

    productFlavors.register("dev") {
        environmentConfig {
            host = "proton.black" // will result in base url https://mail-api.proton.black
        }
    }

    productFlavors.register("atlas") {
        environmentConfig {
            apiPrefix = "test"
            baseUrl = "https://special.url" // will result in base url https://test.special.url
        }
    }
}

Tests

  • Plugin id: me.proton.core.gradle-plugins.tests
  • Published on MavenCentral.

This plugin should be applied to the root build.gradle file. It adds an allTest task which run all unit tests in jvm and Android subprojects.

Release

Release process is based on trunk branch for release process. Release is done by the CI. To trigger a release for version X.Y.Z, just push a branch named release/gradle-plugins/X.Y.Z. When the release is successfully done, a tag release/gradle-plugins/X.Y.Z is created from the commit used to do the release.

Release implementation is orchestrated by project publish-core-plugins.