Sheath
Sheath is a Kotlin compiler plugin created to improve build performances when using Dagger and Dagger-Android. Sheath allows you to generate Factory classes that usually the Dagger annotation processor would generate for @Provides
methods, @Inject
constructors, @Inject
fields and @ContributesAndroidInjector
methods. The benefit of this feature is that you don't need to enable the Dagger annotation processor in this module. That often means you can skip KAPT and the stub generating task. In addition Sheath generates Kotlin instead of Java code, which allows Gradle to skip the Java compilation task. The result is faster builds.
Sheath was forked from Anvil, an amazing project which helped me understanding Kotlin compiler plugins.
Setup
The plugin consists of a Gradle plugin and Kotlin compiler plugin. The Gradle plugin automatically adds the Kotlin compiler plugin and annotation dependencies. It needs to be applied in all modules that either contribute classes to the dependency graph or merge them:
plugins {
id 'dev.quiro.sheath' version "${latest_version}"
}
Or you can use the old way to apply a plugin:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "dev.quiro.sheath:gradle-plugin:${latest_version}"
}
}
apply plugin: 'dev.quiro.sheath'
Performance
Coming soon
Limitations
No Java support
Sheath is a Kotlin compiler plugin, thus Java isn’t supported. You can use Sheath in modules with mixed Java and Kotlin code for Kotlin classes, though.
Incremental Kotlin compilation breaks compiler plugins
There are two bugs that affect the Sheath Kotlin compiler plugin:
- Incremental compilation breaks compiler plugins
- AnalysisResult.RetryWithAdditionalRoots crashes during incremental compilation with java classes in classpath
The Gradle plugin implements workarounds for these bugs, so you shouldn't notice them. Side effects are that incremental Kotlin compilation is disabled for stub generating tasks (which don't run a full compilation before KAPT anyways). The flag usePreciseJavaTracking
is disabled, if the module contains Java code.
License
Copyright 2020 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.