Table of Contents

Benefits Setup Usage

Gradle Plugin Installation

units-of-measure is distributed as a Gradle plugin.

Latest version:

Generated Code Module

Creating a separate Gradle module for units-of-measure’s generated code is highly recommended.

settings.gradle
// ...
include 'uoms'
see full example on GitHub

uoms/build.gradle
plugins {
    id 'info.kunalsheth.units' version 'VERSION'
    id 'org.jetbrains.kotlin.multiplatform'
}

repositories.jcenter()

kotlin {
    jvm()
//  js()
//  linuxX64()

    sourceSets {
        commonMain {
            kotlin.srcDir(generateUnitsOfMeasure.generatedSrcDir)
            dependencies { implementation kotlin('stdlib-common') }
        }
        jvm { dependencies { implementation kotlin('stdlib-jdk8') } }
//      js { dependencies { implementation kotlin('stdlib-js') } }
        all { languageSettings.enableLanguageFeature('InlineClasses') }
    }
    targets.all {
        compilations.all { compileKotlinTask.dependsOn(generateUnitsOfMeasure) }
    }
}
apply from: 'units-of-measure.gradle'
see full example on GitHub

uoms/units-of-measure.gradle
generateUnitsOfMeasure { // see advanced configuration
    // relationships += ...
    // quantities += ...
    // unitsOfMeasure += ...
}
see full example on GitHub

User Application Dependency

myapp/build.gradle
// ...
dependencies {
    api project(':uoms')
    // ...
}
// ...
see full example on GitHub

units-of-measure comes ready to use with common SI units and quantities.

For the following customizations, please edit the uoms/units-of-measure.gradle configuration:

  1. using imperial or non-SI units (e.g. Mile, Degree, Gallon, etc.)
  2. using uncommon quantities (e.g. Absement, VoltageSlewRate, etc.)
  3. shrinking size of compiled binary by fine-tuning which definitions are generated

‹ Benefit: Safe Flexibility Basic Usage ›› Advanced Configuration ›