Releases: gradle/kotlin-dsl-samples
0.3.0
General Notes
Gradle Script Kotlin v0.3.0 significantly improves the support for Kotlin based projects and it is expected to be included in the upcoming Gradle 3.0 RC1.
The features in this release are also available for immediate use within the latest Gradle Script Kotlin distribution nightly. To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-distribution-url https://repo.gradle.org/gradle/kotlin-dsl-snapshots-local/gradle-script-kotlin-3.0.0-20160719234019+0000-bin.zip
Updates since v0.2.1
-
Upgrade to Kotlin 1.1-M01 (#98). The embedded Kotlin compiler was upgraded to the recently released Kotlin 1.1-M01 bringing more language features and a better IDE experience.
-
Kotlin based plugins (#84). A number of issues preventing Kotlin based plugins to be configured from Kotlin based builds have been fixed. Note that the build script will be executed against the version of the Kotlin runtime found in the script classpath which might be older or newer than the one embedded in gradle-script-kotlin.
-
Kotlin based
buildSrc
(#86). Kotlin can now be used as an implementation language inbuildSrc
. The extensionsRepositoryHandler.gradleScriptKotlin
andDependencyHandler.kotlinModule
were introduced to ease the process. A proper sample will be coming soon, in the meantime please refer to this test case. -
Types defined in
buildSrc
are visible to IDEA (#92). Types defined inbuildSrc
will now be recognised by IDEA and content-assist will work. Source navigation support is under way. -
Groovy Closure interoperability helpers (#103). To help in dealing with Groovy specific APIs, the helpers
closureOf
andKotlinClosure
were introduced. This is how a script can react to thebuildFinished
event, for instance:gradle.buildFinished(closureOf<BuildResult> { println("$action finished") // $action refers to BuildResult.getAction() })
0.2.1
General Notes
Gradle Script Kotlin v0.2.1 is an interim release meant to pave the way for the evolution of the org.gradle.configuration.ScriptPluginFactoryProvider
SPI and as such it is incompatible with Gradle 3.0 M2.
The features in this release are only available for use within the latest Gradle Script Kotlin distribution nightly. To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-distribution-url https://repo.gradle.org/gradle/kotlin-dsl-snapshots-local/gradle-script-kotlin-3.0.0-20160707200712+0000-all.zip
Updates since v0.2.0
- Implicit imports for
buildscript
blocks (#90). Members of the commonly-used packagesorg.gradle.script.lang.kotlin
andorg.gradle.api.plugins
are now also imported by default intobuildscript
blocks making all usual extensions and types available everywhere in Kotlin-based Gradle build scripts. - Types defined in
buildSrc
(#38). Types defined inbuildSrc
are now visible to Kotlin-based Gradle build scripts. Proper IDE integration for this feature is still under development. - Compliance with new
ScriptPluginFactoryProvider
SPI semantics (#87). The SPI now favors dependency injection over explicitServiceRegistry
access (to be removed soon from the SPI).
0.2.0
General Notes
Gradle Script Kotlin v0.2.0 is now available for use in Gradle 3.0 M2. To get started, see the samples README.
Updates since v0.1.1
- Build script dependencies and external plugins (#29). Dependencies can now be added to the build script classpath using the
buildscript
block, and any plugins resolved there can be applied using theapply
block. Seesamples/hello-kotlin/build.gradle.kts
for an example. - Seamless project import into IDEA (#26, #43). Importing projects with Kotlin-based builds into IDEA no longer requires running the
generateKtsConfig
andpatchIdeaConfig
tasks, as configuring the Kotlin IDEA plugin and creating an appropriate IDEA library is now handled automatically. Installing the latest dev build of the Kotlin IDEA plugin remains a pre-requisite. Seesamples/README
for complete instructions. - Implicit imports (#33, #57). Members of the commonly-used packages
org.gradle.script.lang.kotlin
andorg.gradle.api.plugins
are now imported by default into all Kotlin-based Gradle build scripts, resulting in less boilerplate. See commita866610
for an example of the difference this creates. - Externally-defined properties (#60). It is now possible to reference project properties by declaring a
val
delegated to the build script's enclosingproject
object. This approach provides a strong contract for which properties should be available to the build script, while remaining agnostic as to how those projects are actually declared—be it viagradle.properties
,-P
flags or otherwise. Seesamples/project-properties/build.gradle.kts
for an example. - Convenient alternatives to string-based dependency configurations (#36). Prior to this release, dependency configurations were expressed as strings, e.g.
"compile"("org.foo:mylib:1.0")
. This approach is still supported, but extension functions such ascompile
andtestCompile
are now available as a a more convenient and tooling-friendly alternative.
0.1.1
UPDATE 2016.06.20: Gradle Script Kotlin version 1.0 M1a
has been renamed to version 0.1.1
. This change is being made to accommodate more frequent feature and patch releases on the road to 1.0
GA. Note that names and versions of published artifacts have not changed. Only the tag and release notes themselves have been updated for consistency and continuity with future 0.*
pre-releases.
General Notes
This patch release upgrades Gradle Script Kotlin's dependency on org.jetbrains:kotlin-compiler-embeddable
from 1.1.0-dev-372
to 1.1.0-dev-372a
. The latter is our own custom patch that removes a problematic META-INF/services
file from the jar that causes failures at Gradle runtime.
This release should be used in favor of 0.1.0
in all cases, and all the features and limitations detailed in the original 0.1.0
release notes still apply.
Fixes since 0.1.0
- #78 Upgrade to manually-patched kotlin-compiler-embeddable jar
0.1.0
UPDATE 2016.06.20: Gradle Script Kotlin version 1.0 M1
has been renamed to version 0.1.0
. This change is being made to accommodate more frequent feature and patch releases on the road to 1.0
GA. Note that names and versions of published artifacts have not changed. Only the tag and release notes themselves have been updated for consistency and continuity with future 0.*
pre-releases.
UPDATE 2016.06.09: Gradle 3.0 M1
has been released, including within it Gradle Script Kotlin 1.0 M1
. This means it is no longer necessary to work with a custom Gradle distribution, and Kotlin scripting is available "out of the box". The instructions below have been updated to reflect.
General Notes
With this first pre-release, Gradle users can now write their build scripts in Kotlin.
Such scripts may technically have any name ending in .kts
, but users may want to consider naming them *.gradle.kts
by convention. For example: build.gradle.kts
.
See the samples for a complete getting started experience and examples of each of the following features.
Gradle Script Kotlin 0.1.0 is available for use within Gradle 3.0 M1. To use it, upgrade your Gradle wrapper to 3.0-milestone-1
in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 3.0-milestone-1
With this wrapper in place and pointing to the custom distribution, you'll be able work with a Kotlin-based build as follows:
$ ./gradlew -b build.gradle.kts yourTask
Note that each of the samples are configured with a wrapper as per the instructions above, and this is why they "just work".
Initial Features
-
Tasks can be declared using the lightweight
task
function. -
Core Gradle plugins, e.g.
JavaPlugin
andApplicationPlugin
can be applied usingapply<PluginType>()
. Resolving and applying external plugins is not yet supported, see Limitations. -
Plugins that publish an associated "convention" objects can be configured using
configure<ConventionType>() { ... }
. -
Build scripts can be modularized using
applyFrom("other.kts")
, and the target script to be applied may be Groovy or Kotlin-based, opening up opportunities for incremental migration. The same is true from the Groovy side:apply from: "other.gradle"
may refer to either Groovy or Kotlin-based scripts. -
Repositories may be declared using
repositories { ... }
-
Dependencies may be declared using
dependencies { ... }
and individual dependency declarations following the form"compile"("group:artifact:1.0")
. -
A variety of tooling use cases work as expected within IDEA (2016.1.2 or better), including:
- Project import (a
settings.gradle
file is required, see Limitations) - Quick documentation with
F1
/CTRL-J
- Navigation to source with
CMD-B
- Auto-completion / content-assist with
CTRL-SPACE
- Refactoring actions
For best results within IDEA, follow the setup instructions in the samples README.
- Project import (a
Limitations
-
settings.gradle
cannot yet be written Kotlin, continue to use Groovy there for now. -
Gradle does not yet have auto-detection of Kotlin-based build scripts, meaning you must either:
a. use
gradle -b build.gradle.kts
, orb. add
rootProject.buildFileName='build.gradle.kts'
to yoursettings.gradle
file.Due to this limitation, importing projects into IDEA currently requires the presence of a
settings.gradle
in order for IDEA to recognize the project as a Gradle project -
There is not yet support for additions to the
buildscript
classpath. This means that there there is not yet support for resolving external plugins. Naturally, this is a high priority for the next milestone. -
For a complete, error-free experience in IDEA, it is necessary to run
./gradlew generateKtsConfig
prior to importing your project into IDEA, and it is necessary to run./gradlew patchIdeaConfig
after importing your project. Both of these workarounds will be unnecessary in future milestones. See the the samples README for step-by-step instructions on how to do this. -
There is not yet any support for caching Kotlin-based build scripts, meaning that they must be compiled on every build. For this reason, expect most simple Kotlin-based builds to be marginally slower that an equivalent Groovy-based build.
1.0 M1a
UPDATE 2016.06.20: Version 1.0 M1a has been renamed to version 0.1.1. See the 0.1.1 release notes for details.
1.0 M1
UPDATE 2016.06.20: Version 1.0 M1 has been renamed to version 0.1.0. See the 0.1.0 release notes for details.