Skip to content

Domain plugin

Add the following to the root build.gradle or build.gradle.kts to apply the plugin:

plugins {
    id("com.freeletics.gradle.domain").version("<latest-version>")
}

Default configurations

Common configuration

The plugin applies the following common configuration:

  • The Java and Kotlin toolchain are set to the java-toolchain version catalog version.
  • Kotlin’s progressive mode is enabled.
  • Kotlin compiler warnings are treated as errors.
    • This can be disabled by setting fgp.kotlin.warningsAsErrors=false
    • It’s possible to ignore deprecation warning by setting fgp.kotlin.suppressDeprecationWarnings=true
  • Several Kotlin compiler flags are set to improve the default behavior.
  • All produced archives are configured to be reproducible.

Default dependencies

The plugins can dynamically add default dependencies to all modules. This can be enabled by creating any of the following bundles:

[bundles]
# any dependency in this bundle is automatically added to all modules as implementation dependency
default-all = [ ... ]
# any dependency in this bundle is automatically added to all modules as compileOnly dependency
default-all-compile = [ ... ]
# any dependency in this bundle is automatically added to all Android modules as implementation dependency
default-android = [ ... ]
# any dependency in this bundle is automatically added to all Android modules as compileOnly dependency
default-android-compile = [ ... ]
# any dependency in this bundle is automatically added to all modules as testImplementation dependency
default-testing = [ ... ]
# any dependency in this bundle is automatically added to all modules as testCompileOnly dependency
default-testing-compile = [ ... ]
# any dependency in this bundle is automatically added to all modules as testRuntimeOnly dependency
default-testing-runtime = [ ... ]
# any dependency in this bundle is automatically added to all modules as lintChecks dependency
default-lint = [ ... ]

Multiplatform Kotlin configuration

  • The default hierarchy template is applied automatically.
  • expect and actual classes are enabled in compiler through the -Xexpect-actual-classes option.
  • Android Lint is applied to the module.

Android target configuration

If an Android target is added:

  • The compileSdk is set to the android-compile version catalog version
  • The minSdk is set to the android-min version catalog version
  • Optionally the buildToolsVersion is set to the android-buildTools version catalog version if it’s present in the version catalog.
  • If the android-desugarjdklibs library is defined the version catalog core library desugaring is be enabled automatically.
  • Host tests are enabled.

Features

Explicit API

It’s possible to enable Kotlin’s explicit API mode directly from the DSL by calling:

freeletics {
    explicitApi()
}

Experimental API opt in

It’s possible to opt into an experimental API for the module directly from the DSL by calling:

freeletics {
    optIn("...")
}

Compose

To enable Jetpack Compose for the module call:

freeletics {
    useCompose()
}

It’s possible to enable compose compiler reports and metrics by setting the following 2 properties. Afterwards the outputs can be found in the build folder.

fgp.compose.enableCompilerMetrics=true
fgp.compose.enableCompilerReports=true`

kotlinx.serialization

To enable kotlinx.serialziation for the module call:

freeletics {
    useSerialization()
}

This expects the version catalog to have a kotlinx-serialization entry with the org.jetbrains.kotlinx:kotlinx-serialization-core library.

Metro

To enable Metro for the module call:

freeletics {
    useMetro()
}

Khonshu

To enable Khonshu for the module call:

freeletics {
    useKhonshu()
}

Both Metro and KSP will be automatically enabled when using Khonshu.

This expects the version catalog to have the following 2 entries: - khonshu-codegen-runtime pointing to com.freeletics.khonshu:codegen-runtime - khonshu-codegen-compiler pointing to com.freeletics.khonshu:codegen-compiler

Poko

To enable Poko for the module call:

freeletics {
    usePoko()
}

Kopy

To enable Kopy for the module call:

freeletics {
    useKopy()
}

SQLDelight

To enable SQLDelight for the module call:

freeletics {
    useSqlDelight()
}

There are 2 optional parameters for this function: - the name for the generated database which defaults to database - a dependency if this module depends on another module’s SQLDelight definitions

To change the used SQL dialect add the dialect of your choice to the version catalog with an entry called sqldelight-dialect.

Room

To enable Room for the module call:

freeletics {
    useRoom()
}

This will automatically apply KSP to the project and will use Kotlin code generation.

Optionally a schemaLocation can be provided.

This expects the version catalog to have the following 2 entries: - androidx-room-runtime pointing to androidx.room:room-runtime - androidx-room-compiler pointing to androidx.room:room-compiler

Burst

To enable Burst for the module call:

freeletics {
    useBurst()
}

OSS publishing

Publishing to Maven Central using the gradle-maven-publish-plugin.

freeletics {
    enableOssPublishing()
}

Enabling this will also apply Dokka, enable ABI validation and enable explicit API mode.

For the configuration of the POM, only the following Gradle properties need to be defined: - GROUP - VERSION_NAME - POM_REPO_NAME - POM_ARTIFACT_ID - POM_NAME - POM_DESCRIPTION

Internal publishing

Publishing to an internal repo can be enabled by calling the following function:

freeletics {
    enableInternalPublishing()
}

A fgp.internalArtifacts.url gradle property needs to be defined with the URL of the remote repository. The username and password for this repository are expected to be set through internalArtifactsUsername and internalArtifactsPassword.

Adding multiplatform targets

There are several functions to easily add targets to the module:

freeletics {
    multiplatform {
        // adds all targets that a also supported by the coroutines project
        // has a `limitToComposeTargets` boolean parameter that can be set to true to only add targets supported by
        // the compose runtime
        addCommonTargets()
        // adds jvm as a target
        addJvmTarget()
        // adds Android as a target
        addAndroidTarget {
            // Android DSL options
        }
        // adds `iosArm64`, `iosSimulatorArm64` as targets
        // has a `includeX64` boolean parameter to also include `iosX64`
        addIosTargets()
        // same as above but will also configure everything to create a XCFramework
        addIosTargetsWithXcFramework("frameworkName") { framework ->
            // optionally configure the framework
        }
    }
}

Compose resources

Enable Compose resources for the module call:

freeletics {
    multiplatform {
        useComposeResources()
    }
}

This will configure the Res class generation to always run and will configure the package name based on the module.

SKIE

To enable SKIE for the module call:

freeletics {
    useSkie()
}

Paparazzi

To enable Paparazzi for the module call:

freeletics {
    android {
        usePaparazzi()
    }
}

This also configures that running Gradle’s check or build tasks will automatically include verifyPaparazzi.

Parcelize

To enable Parcelize for the module call:

freeletics {
    android {
        enableParcelize()
    }
}

Android resources

To enable Android resources for the module call:

freeletics {
    android {
        enableAndroidResources()
    }
}

–8← “docs/features/multiplatform-android-4-proguard.md)