• Stars
    star
    795
  • Rank 57,274 (Top 2 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created almost 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Public API management tool

Kotlin Alpha JetBrains official project Apache license

Binary compatibility validator

The tool allows dumping binary API of a JVM part of a Kotlin library that is public in the sense of Kotlin visibilities and ensures that the public binary API wasn't changed in a way that makes this change binary incompatible.

Contents

Setup

Binary compatibility validator is a Gradle plugin that can be added to your build in the following way:

  • in build.gradle.kts
plugins {
    id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
}
  • in build.gradle
plugins {
    id 'org.jetbrains.kotlinx.binary-compatibility-validator' version '0.13.2'
}

It is enough to apply the plugin only to the root project build file; all sub-projects will be configured automatically.

Tasks

The plugin provides two tasks:

  • apiDump — builds the project and dumps its public API in project api subfolder. API is dumped in a human-readable format. If API dump already exists, it will be overwritten.
  • apiCheck — builds the project and checks that project's public API is the same as golden value in project api subfolder. This task is automatically inserted into check pipeline, so both build and check tasks will start checking public API upon their execution.

For projects with multiple JVM targets, multiple subfolders will be created, e.g. api/jvm and api/android

Optional parameters

Binary compatibility validator can be additionally configured with the following DSL:

Groovy

apiValidation {
    /**
     * Packages that are excluded from public API dumps even if they
     * contain public API. 
     */
    ignoredPackages += ["kotlinx.coroutines.internal"]

    /**
     * Sub-projects that are excluded from API validation 
     */
    ignoredProjects += ["benchmarks", "examples"]

    /**
     * Classes (fully qualified) that are excluded from public API dumps even if they
     * contain public API.
     */
    ignoredClasses += ["com.company.BuildConfig"]

    /**
     * Set of annotations that exclude API from being public.
     * Typically, it is all kinds of `@InternalApi` annotations that mark 
     * effectively private API that cannot be actually private for technical reasons.
     */
    nonPublicMarkers += ["my.package.MyInternalApiAnnotation"]

    /**
     * Flag to programmatically disable compatibility validator
     */
    validationDisabled = true
}

Kotlin

apiValidation {
    /**
     * Packages that are excluded from public API dumps even if they
     * contain public API.
     */
    ignoredPackages.add("kotlinx.coroutines.internal")

    /**
     * Sub-projects that are excluded from API validation
     */
    ignoredProjects.addAll(listOf("benchmarks", "examples"))

    /**
     * Classes (fully qualified) that are excluded from public API dumps even if they
     * contain public API.
     */
    ignoredClasses.add("com.company.BuildConfig")
    
    /**
     * Set of annotations that exclude API from being public.
     * Typically, it is all kinds of `@InternalApi` annotations that mark
     * effectively private API that cannot be actually private for technical reasons.
     */
    nonPublicMarkers.add("my.package.MyInternalApiAnnotation")

    /**
     * Flag to programmatically disable compatibility validator
     */
    validationDisabled = false
}

Producing dump of a jar

By default, binary compatibility validator analyzes project output class files from build/classes directory when building an API dump. If you pack these classes into an output jar not in a regular way, for example, by excluding certain classes, applying shadow plugin, and so on, the API dump built from the original class files may no longer reflect the resulting jar contents accurately. In that case, it makes sense to use the resulting jar as an input of the apuBuild task:

Kotlin

tasks {
    apiBuild {
        // "jar" here is the name of the default Jar task producing the resulting jar file
        // in a multiplatform project it can be named "jvmJar"
        // if you applied the shadow plugin, it creates the "shadowJar" task that produces the transformed jar
        inputJar.value(jar.flatMap { it.archiveFile })
    }
}

Workflow

When starting to validate your library public API, we recommend the following workflow:

  • Preparation phase (one-time action):

    • As the first step, apply the plugin, configure it and execute apiDump.
    • Validate your public API manually.
    • Commit .api files to your VCS.
    • At this moment, default check task will validate public API along with test run and will fail the build if API differs.
  • Regular workflow

    • When doing code changes that do not imply any changes in public API, no additional actions should be performed. check task on your CI will validate everything.
    • When doing code changes that imply changes in public API, whether it is a new API or adjustments in existing one, check task will start to fail. apiDump should be executed manually, the resulting diff in .api file should be verified: only signatures you expected to change should be changed.
    • Commit the resulting .api diff along with code changes.

What constitutes the public API

Classes

A class is considered to be effectively public if all the following conditions are met:

  • it has public or protected JVM access (ACC_PUBLIC or ACC_PROTECTED)
  • it has one of the following visibilities in Kotlin:
    • no visibility (means no Kotlin declaration corresponds to this compiled class)
    • public
    • protected
    • internal, only in case if the class is annotated with PublishedApi
  • it isn't a local class
  • it isn't a synthetic class with mappings for when tableswitches ($WhenMappings)
  • it contains at least one effectively public member, in case if the class corresponds to a kotlin file with top-level members or a multifile facade
  • in case if the class is a member in another class, it is contained in the effectively public class
  • in case if the class is a protected member in another class, it is contained in the non-final class

Members

A member of the class (i.e. a field or a method) is considered to be effectively public if all the following conditions are met:

  • it has public or protected JVM access (ACC_PUBLIC or ACC_PROTECTED)

  • it has one of the following visibilities in Kotlin:

    • no visibility (means no Kotlin declaration corresponds to this class member)
    • public
    • protected
    • internal, only in case if the class is annotated with PublishedApi

    Note that Kotlin visibility of a field exposed by lateinit property is the visibility of its setter.

  • in case if the member is protected, it is contained in non-final class

  • it isn't a synthetic access method for a private field

What makes an incompatible change to the public binary API

Class changes

For a class a binary incompatible change is:

  • changing the full class name (including package and containing classes)
  • changing the superclass, so that the class no longer has the previous superclass in the inheritance chain
  • changing the set of implemented interfaces so that the class no longer implements interfaces it had implemented before
  • changing one of the following access flags:
    • ACC_PUBLIC, ACC_PROTECTED, ACC_PRIVATE — lessening the class visibility
    • ACC_FINAL — making non-final class final
    • ACC_ABSTRACT — making non-abstract class abstract
    • ACC_INTERFACE — changing class to interface and vice versa
    • ACC_ANNOTATION — changing annotation to interface and vice versa

Class member changes

For a class member a binary incompatible change is:

  • changing its name
  • changing its descriptor (erased return type and parameter types for methods); this includes changing field to method and vice versa
  • changing one of the following access flags:
    • ACC_PUBLIC, ACC_PROTECTED, ACC_PRIVATE — lessening the member visibility
    • ACC_FINAL — making non-final field or method final
    • ACC_ABSTRACT — making non-abstract method abstract
    • ACC_STATIC — changing instance member to static and vice versa

Building the project locally

In order to build and run tests in the project in IDE, two prerequisites are required:

  • Java 11 or above in order to use the latest ASM
  • All build actions in the IDE should be delegated to Gradle

More Repositories

1

anko

Pleasant Android application development
Kotlin
15,927
star
2

kotlinx.coroutines

Library support for Kotlin coroutines
Kotlin
12,203
star
3

kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Kotlin
5,375
star
4

dokka

API documentation engine for Kotlin
Kotlin
3,311
star
5

kotlin-examples

Various examples for Kotlin
3,177
star
6

KEEP

Kotlin Evolution and Enhancement Process
Markdown
3,109
star
7

kotlin-koans

Kotlin workshop
Kotlin
2,602
star
8

kotlinx-datetime

KotlinX multiplatform date/time library
Kotlin
2,379
star
9

kmp-production-sample

This is an open-source, mobile, cross-platform application built with Kotlin Multiplatform Mobile. It's a simple RSS reader, and you can download it from the App Store and Google Play. It's been designed to demonstrate how KMM can be used in real production projects.
Kotlin
1,984
star
10

kotlindl

High-level Deep Learning Framework written in Kotlin and inspired by Keras
Kotlin
1,467
star
11

coroutines-examples

Examples for coroutines design in Kotlin
1,465
star
12

kotlinx-kover

Kotlin
1,324
star
13

kotlin-fullstack-sample

Kotlin Full-stack Application Example
Kotlin
1,218
star
14

kotlinx.collections.immutable

Immutable persistent collections for Kotlin
Kotlin
1,153
star
15

kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Kotlin
1,094
star
16

kotlinx-cli

Pure Kotlin implementation of a generic CLI parser.
Kotlin
906
star
17

kmm-basic-sample

Example of Kotlin multiplatform project
Kotlin
887
star
18

dataframe

Structured data processing in Kotlin
Kotlin
831
star
19

kotlinx-io

Kotlin multiplatform I/O library
Kotlin
817
star
20

kotlinx-rpc

Add asynchronous RPC services to your multiplatform applications.
Kotlin
730
star
21

kotlinx-atomicfu

The idiomatic way to use atomic operations in Kotlin
Kotlin
716
star
22

kotlinconf-spinner

Kotlin
603
star
23

workshop

JetBrains Kotlin Workshop Material
Kotlin
594
star
24

kotlin-interactive-shell

Kotlin Language Interactive Shell
Java
591
star
25

kdoctor

Environment analysis tool
Kotlin
580
star
26

kandy

Kotlin plotting library.
Kotlin
579
star
27

kotlin-frontend-plugin

Gradle Kotlin (http://kotlinlang.org) plugin for frontend development
Kotlin
570
star
28

dukat

Converter of <any kind of declarations> to Kotlin external declarations
Kotlin
552
star
29

multik

Kotlin
550
star
30

kotlin-wasm-examples

Examples with Kotlin/Wasm
519
star
31

kotlinx-benchmark

Kotlin multiplatform benchmarking toolkit
Kotlin
504
star
32

kotlin-spark-api

This projects gives Kotlin bindings and several extensions for Apache Spark. We are looking to have this as a part of Apache Spark 3.x
Kotlin
459
star
33

kotlin-by-example

The sources of Kotlin by Example.
396
star
34

kotlin-spec

Kotlin Language Specification:
Kotlin
358
star
35

kotlin-in-action

Code samples from the "Kotlin in Action" book
Kotlin
343
star
36

ts2kt

ts2kt is officially deprecated, please use https://github.com/Kotlin/dukat instead. // Converter of TypeScript definition files to Kotlin external declarations
Kotlin
320
star
37

kotlin-numpy

Kotlin bindings for NumPy
Kotlin
312
star
38

kotlin-style-guide

Work-in-progress notes for the Kotlin style guide
289
star
39

kotlinx-knit

Kotlin source code documentation management tool
Kotlin
287
star
40

anko-example

A small application built with Anko DSL
Kotlin
285
star
41

full-stack-web-jetbrains-night-sample

Full-stack demo application written with Kotlin MPP
Kotlin
271
star
42

KMP-App-Template

Kotlin Multiplatform app template with shared UI
Kotlin
269
star
43

kotlin-script-examples

Examples of Kotlin Scripts and usages of the Kotlin Scripting API
Kotlin
262
star
44

kotlinx-nodejs

Kotlin external declarations for using the Node.js API from Kotlin code targeting JavaScript
Kotlin
212
star
45

kotlin-eclipse

Kotlin Plugin for Eclipse
Kotlin
186
star
46

Storytale

Kotlin
165
star
47

kotlinx.reflect.lite

Lightweight library allowing to introspect basic stuff about Kotlin symbols
Kotlin
150
star
48

api-guidelines

Best practices to consider when writing an API for your library
144
star
49

kotlin-benchmarks

This is the project to verify and investigate performance issues in Kotlin and standard library.
Kotlin
136
star
50

kotlin-libs-publisher

Gradle plugin for publishing of Kotlin libs
Kotlin
119
star
51

kotlinx-browser

Kotlin browser API
Kotlin
110
star
52

kotlindl-app-sample

This repo demonstrates how to use KotlinDL for neural network inference on Android devices.
Kotlin
96
star
53

kotlin-koans-edu

Kotlin Koans for Educational Plugin and play.kotl.in
Kotlin
93
star
54

KMP-App-Template-Native

Kotlin Multiplatform app template with native UI
Kotlin
85
star
55

grammar-tools

Tokenization and parsing Kotlin code using the ANTLR Kotlin grammar
Kotlin
83
star
56

kmm-integration-sample

Kotlin
76
star
57

kmm-with-cocoapods-sample

This project represents the case when Cocoapods dependencies are added in Kotlin and there is no existing Xcode project
Kotlin
57
star
58

kotlin-koans-edu-obsolete

Obsolete: check https://github.com/Kotlin/kotlin-koans-edu for the latest version.
Kotlin
55
star
59

kotlin-native-calculator-sample

55
star
60

kotlinx.support

Extension and top-level functions to use JDK7/JDK8 features in Kotlin 1.0
Kotlin
54
star
61

js-externals

External declarations for Kotlin/JS
53
star
62

k2-performance-metrics

Measure Kotlin K2 compiler performance in your repository
Jupyter Notebook
45
star
63

kmp-native-wizard

A mostly-empty template to get started creating a Kotlin/Native project.
Kotlin
43
star
64

coroutines-workshop

Materials for a full-day workshop on Kotlin Coroutines
Kotlin
42
star
65

swift-export-sample

Kotlin to Swift technology preview
Swift
39
star
66

kotlin-playground-wp-plugin

WordPress plugin which allows to embed interactive Kotlin playground to any post via [kotlin] shortcode
PHP
35
star
67

io2019-serverside-demo

E2E Sample
Kotlin
31
star
68

kotlin-jupyter-libraries

Library descriptors for Kotlin kernel for Jupyter
29
star
69

kmm-with-cocoapods-multitarget-xcode-sample

This project is intended to demonstrate how to connect Kotlin library to Xcode project with several targets: iOS, macOS, tvOS, watchOS
Swift
23
star
70

xcode-compat

AppCode helper for Kotlin/Native and Xcode
Kotlin
21
star
71

kotlin-in-action-2e

Code samples for the second edition of "Kotlin in Action".
Kotlin
20
star
72

kotlin-wasm-compose-template

A template repository for Compose Multiplatform with Kotlin/Wasm target
Kotlin
20
star
73

kotlinx.dom

Kotlin
17
star
74

kotlin-wasm-benchmarks

Kotlin Multiplatform Collection of Benchmarks focused on Kotlin/Wasm performance
Kotlin
13
star
75

dokka-plugin-template

Dokka plugin quickstart template with pre-configured dependencies and publishing
Kotlin
12
star
76

kotlinx.team.infra

Kotlin
10
star
77

multiplatform-library-template

Kotlin
10
star
78

kotlin-js-inspection-pack-plugin

Adds useful inspections, intentions, and quick-fixes for working with Kotlin/JS projects.
Kotlin
10
star
79

obsolete-kotlin-swing

Experimental library providing some helper functions and extensions for creating Swing user interfaces.
Kotlin
8
star
80

kotlin-in-action-2e-jkid

Sample project accompanying the second edition of "Kotlin in Action". JSON serialization/deserialization library for Kotlin data classes
Kotlin
8
star
81

kotlin-wasm-browser-template

A template repository for Kotlin/Wasm on browser
HTML
8
star
82

kotlin-spark-shell

Kotlin Language support for Apache Spark
Kotlin
7
star
83

obsolete-kotlin-jdbc

Experimental library providing some helper functions and extensions for working with JDBC in Kotlin.
Kotlin
7
star
84

community-project-gradle-plugin

Kotlin
6
star
85

website-grammar-generator

Kotlin ANTLR grammar converter to XML for the Kotlin website or text file
Kotlin
6
star
86

kotlin-grammar-gpl2

Kotlin grammar ANTLR sources (under GPLv2)
ANTLR
6
star
87

web-site-samples

Examples repository for kotlinlang.org
4
star
88

kotlin-build-report-sample

Kotlin
4
star
89

kotlin-wasm-wasi-template

A template repository for Kotlin/Wasm with WASI
Kotlin
4
star
90

kotlin-jupyter-http-util

Ktor client and serialization for Kotlin Jupyter Notebooks
Kotlin
3
star
91

kotlin-cocoapods-spec

Ruby
3
star
92

analysis-api

Kotlin Analysis API Documentation
3
star
93

kotlin.github.io

Redirect to kotlinlang.org and favicon/title provider for kotlin.github.io/* websites.
HTML
2
star
94

kotlin-wasm-nodejs-template

A template repository for Kotlin/Wasm on Node.js
Kotlin
1
star
95

kmm-with-cocoapods-xcode-two-kotlin-libraries-sample

This project is intended to demonstrate the connection of two Kotlin libraries to existing Xcode project through Cocoapods
Kotlin
1
star