Releases: gradle/kotlin-dsl-samples
1.1.3
Gradle Kotlin DSL 1.1.3 Release Notes
Gradle Kotlin DSL 1.1.3 brings bug fixes and the latest Kotlin release.
v1.1.3 is included in Gradle 5.2.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.2 --distribution-type all
Updates since v1.1.1 (Gradle 5.1.1)
-
Kotlin 1.3.20 (#1325)
Please see the Kotlin 1.3.20 announcement for details.
-
IDEA editing support is broken in 5.1 if gradle project root is not the same as IDEA project root (#1308, #1321)
A problem in the serialization of the TAPI model describing the script classpath given to IDEA affecting Java 11 users was identified and fixed.
-
Script >64KB leads to Could not open cache directory (#1305, #1323)
The Gradle Kotlin DSL script compiler caches a preprocessed version of a script to speed up its repeated evaluation.
In previous versions, the processed version was always stored as a string constant in a Java class file which imposes a 64KB limit on such constants.
Starting with v1.1.3, large strings are stored as external resources and no longer have a predetermined size limit.
-
Generated Plugin source is not removed if precompiled script plugin is deleted (#1306, #1316)
The
kotlin-dsl
plugin will now correctly remove any stale outputs from a previous run.
For the complete list see the gradle/kotlin-dsl
issues for 1.1.3.
1.1.1
Gradle Kotlin DSL 1.1.1 Release Notes
Gradle Kotlin DSL 1.1.1 fixes issues around type-safe accessors generation correctness and introduces a missing reified generic Kotlin extension to create MapProperty
objects.
v1.1.1 is included in Gradle 5.1.1.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.1.1 --distribution-type all
Updates since v1.1.0 (Gradle 5.1)
-
Add convenience method for
MapProperty
introduced in 5.1 (#1307)The new method makes working with map inputs a little more convenient:
open class Generator : DefaultTask() { @Input val properties = project.objects.mapProperty<String, Int>() @TaskAction fun generate() { properties.get().forEach { (key, value) -> logger.quiet("$key = $value") } } }
-
Caching of type-safe model accessors didn't take differences in container elements into account (#1303, #1304)
In order to speed up the compilation of Kotlin DSL build scripts and amortise the cost of the required code generation step, the Kotlin DSL script compiler tries to maximise the reuse of generated type-safe model accessors across projects and builds.
It does that by caching the generated code based on a key defined by, among other things, the set of accessible Gradle model elements in the target project.
In previous versions however, the cache key definition was missing elements from Gradle model containers such as
tasks
andsourceSets
which would cause accessors generated for one project to be (wrongly) reused for another project when they differed only in the set of accessible container elements.This defect has been fixed.
For the complete list see the gradle/kotlin-dsl
issues for 1.1.1.
1.1.0
Gradle Kotlin DSL 1.1.0 Release Notes
Gradle Kotlin DSL 1.1.0 brings Kotlin 1.3.11, support for Kotlin lambdas in the Gradle APIs, multiple fixes and enhancements for a better behavior in IntelliJ script dependency resolution, bug fixes in the kotlin-dsl
plugin for build authors, selected type-safe accessors additions and better build-cache support.
In order to benefit from the best user experience, please update IntelliJ IDEA to 2018.3.1, Android Studio to 3.3 and their Kotlin Plugin to the latest 1.3.
v1.1.0 is included in Gradle 5.1.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.1 --distribution-type all
Updates since v1.0.4 (Gradle 5.0)
-
Kotlin 1.3.11 (#1285)
Please see the Kotlin 1.3.11 release notes for more information.
-
Gradle APIs now accept Kotlin lambdas (#1077)
Gradle API members accepting
Any
and unpacking Groovy closures and Callables lazily now also accept Kotlin lambdas. Instead offile(Callable { "foo" }) files(Callable { "bar" }) copy { from(Callable { "compute/inputs/lazily" }) // ... }
it is now possible to write:
file({ "foo" }) files({ "bar" }) copy { from({ "compute/inputs/lazily" }) // ... }
-
Type-safe accessors for configurations in
artifacts {}
(#889, #1020, #1276)The
artifacts {}
block now has type-safe accessors to add artifacts to existing configurations. Instead ofartifacts { add("archives", tasks.jar) }
it is now possible to write:
artifacts { archives(tasks.jar) }
-
Type-safe accessors for extensions in
dependencies {}
(#1185, #1190, #1278)The
dependencies {}
block now has type-safe accessors to existing extensions. For example, given an existing extension on theDependencyHandler
namedacme
and providing dependencies declarations one could now write:dependencies { implementation(acme.core) }
-
Script compilation and
kotlin-dsl
plugin tasks cached outputs can now be shared (#1286, #1288)All the generated code is now reproducible byte to byte allowing the Gradle Build Cache support to share the cached outputs between different operating systems.
-
kotlin-dsl
plugin tasks are now all cacheable (#1243, #1275)The
:generateScriptPluginAdapters
task contributed by thekotlin-dsl
plugin is now cacheable, relocatable and its outputs can be shared between different operating systems. -
kotlin-dsl
plugin now sets KotlinapiVersion
andlanguageVersion
to1.3
(#1274, #1277)For uniformity with script compilation.
-
IDE editor script dependencies is now correct for scripts outside the project root (#1231, #1289)
Prior to this release, when the layout of a build included subprojects stored outside the build root directory, the script dependencies resolver wouldn't consider those subprojects to be part of the imported project. Instead, the subprojects would be treated as standalone projects most likely causing the wrong classpath to be served to the IDE.
For example, in the following Gradle build layout where
root
is the actual Gradle root project directory imported into IntelliJ IDEA andp1
is a subproject outside theroot
directory tree:├── root │ ├── build.gradle.kts │ ├── buildSrc │ │ └── build.gradle.kts │ └── settings.gradle.kts └── p1 └── build.gradle.kts
With the old and incorrect behaviour, IntelliJ IDEA would receive the wrong classpath for the
p1/build.gradle.kts
script which was treated as a script plugin with no connection to thep1
subproject.This behaviour has been fixed and now scripts for subprojects stored outside the imported project root directory will be correctly recognised as such.
-
IDE editor script dependencies resolution consumes less resources (#1155)
When editing a
.gradle.kts
script in IntelliJ IDEA, resolving the script classpath for the first time can take a relatively long time due to the downloading of dependencies and their sources (including the Gradle sources if using a -bin distribution).Making changes to a script while a resolution request is pending causes further requests to be enqueued for later processing.
Prior to this release, the Kotlin DSL would simply serve all pending requests one by one which could end up consuming a lot of resources unnecessarily considering that repeated requests for the uptodate classpath of the same script only needs to be resolved once.
Starting with this release, the Kotlin DSL script dependencies resolver will only process the most recent request for each script avoiding a lot of unnecessary work.
-
IDE editor script dependencies resolution now better manage its logs (#1267, #1273, #1280, #1281)
On Windows, the log directory moved from
$HOME/Application Data/gradle-kotlin-dsl/log
to the more idiomatic and always local$HOME/AppData/Local/gradle-kotlin-dsl/log
.On all systems, the log directory is now checked periodically (at most every 24 hours) and log files are deleted if they are more than 7 days old.
For the complete list see the gradle/kotlin-dsl
issues for 1.1.0.
1.0.4
Gradle Kotlin DSL 1.0 Release Notes
Gradle Kotlin DSL 1.0 brings Kotlin 1.3.10, performance improvements, script compilation build cache, API/DSL refinements and fixes.
In order to benefit from the best user experience, please update IntelliJ IDEA to 2018.3, Android Studio to 3.2 and their Kotlin Plugin to the latest 1.3.
Thanks to a great help from the community, the Gradle User Manual now contains samples for both the Groovy and Kotlin DSLs. This is now the best place to find information on how to use the Gradle Kotlin DSL as it covers all Gradle features from using plugins to customizing the dependency resolution behavior.
A new user manual chapter dedicated to the Gradle Kotlin DSL has also been added.
The Gradle Plugin Portal now displays Kotlin DSL snippets for easy copy and paste.
This release contains potential breaking changes, see below.
v1.0.4 is included in Gradle 5.0.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.0 --distribution-type all
Updates since v1.0.3 (Gradle 5.0 RC3)
-
Kotlin 1.3.10 (#1248)
Please see the Kotlin 1.3.10 release notes for more information.
-
Reduce code generation overhead (#1202)
Starting with this release, at most a single IO thread will be used during the code generation phase of script compilation.
For the complete list see the gradle/kotlin-dsl
issues for 1.0.4.
Updates since v1.0.2 (Gradle 5.0 RC2)
-
Let
getting
property delegate usegetByName()
instead ofnamed()
(#1247) -
Let
creating
property delegate usecreate()
instead ofregister()
(#1246)
For the complete list see the gradle/kotlin-dsl
issues for 1.0.3.
Updates since v1.0-RC14 (Gradle 5.0 RC1)
-
Let generated source code import default package types (#1205, #1239)
-
The
kotlin-dsl
plugin don't pin kotlin dependencies anymore (#1241)
For the complete list see the gradle/kotlin-dsl
issues for 1.0.2.
Updates since v1.0-RC12 (Gradle 5.0 M1)
-
Upgrade embedded Kotlin to 1.3.0 (#1197)
Please see the Kotlin 1.3 announcement, What’s New page, ChangeLog and Compatibility Guide for more information.
-
Faster script compilation (#1168, #817, #1199)
The biggest bottleneck in the Gradle Kotlin DSL was the compilation of the generated Kotlin type-safe accessors during script compilation. The most impacted use cases were first time use of a build, and, the feedback loop when making changes to the build logic, both from the command line or in the script editor.
In this release we replaced the usage of the Kotlin compiler for this particular step by generating the bytecode directly instead. The generated accessors are lean and repetitive, no need for a full-blown compiler to produce their bytecode.
The IDE experience is preserved, you can still display accessors documentation in context and navigate to their sources.
On the
gradle/kotlin-dsl
build with a dozen projects and a fair amount of custom build logic, the feedback loop on API change inbuildSrc
went from ~10s to ~6s. That's a 40% improvement.On a small Android application, here the Android Sunflower sample application, the feedback loop on API change in
buildSrc
went from ~7s down to ~4.5s. That's a 40% improvement too.The effect is even more drastic on complex builds. On the
gradle/gradle
build that has almost a hundred projects and a fairly complex build logic, the feedback loop on API change inbuildSrc
went from ~1 minute down to ~25s. That's a 60% improvement.That change has about the same effect on the clean checkout use case, and, improves the first time use of a small build by ~20%. For all use cases, the larger the build, bigger is the impact.
-
Fix Gradle daemon meta space leak caused by
kotlin-dsl
plugin (#1188)A permanent generation / meta space memory leak was introduced in 1.0 RC1 causing the Gradle daemon to consume spurious memory and eventually fail with
OutOfMemoryError
. This is now fixed. See the linked issue for the tasty details. -
IDE script resolver skip buildSrc verification tasks (#1174)
In order to shorten the feedback loop in the
.gradle.kts
editor, the script dependencies resolver now skips all verification tasks from thebuildSrc
build if present. -
Generate compilable container elements accessors for element with type in the default package (#1158, #1162, #1164)
Previous release introduced type-safe accessors for elements of containers (e.g.
tasks.compileJava { }
) but they were not compilable and caused builds to fail when the element type was from the default package. This is now fixed.
For the complete list see the gradle/kotlin-dsl
issues for 1.0-RC14.
Updates since v1.0-RC6 (Gradle 4.10.2)
-
Upgrade embedded Kotlin to 1.3.0-RC2 (#1149, #1005, #1112, #1125, #1132)
Note that Gradle Kotlin DSL 1.0 will ship with Kotlin 1.3 GA.
-
Script compilation build cache is now enabled alongside the Gradle Build Cache (#1152)
If you enable the Gradle Build Cache then the Gradle Kotlin DSL will store and fetch the outputs of script compilation, avoiding the expensive work of recompiling them.
-
Accessors for plugins present in
buildSrc
(#1156)You can now refer statically to plugins declared in
buildSrc
. Instead of:plugins { id("my.buildSrc.plugin.ID") }
you can now write:
plugins { my.buildSrc.plugin.ID }
-
Accessors for elements of collections (#879, #1041)
It is now possible to refer to elements of collections available at build script body compilation time via type-safe accessors. This is applied to
configurations
,tasks
and all Gradle extensions that are collections such assourceSets
. Fortasks
, it means that instead of writing:plugins { java } tasks { named<Test>("test") { testLogging.showStacktraces = true } }
you can now write:
plugins { java } tasks { test { testLogging.showStacktraces = true } }
-
Accessors for artifact configurations in
configurations {}
(#1118, #1129)Accessors for artifact configurations were missing in the
configurations {}
block. This has been fixed the same way as for all collections, see above. Instead of:plugins { java } configurations { named("implementation") { exclude(group = "org.foo") } }
you can now write:
plugins { java } configurations { implementation { exclude(group = "org.foo") } }
-
Refine dependency constraints DSL (#710, [#...
1.0.3
Gradle Kotlin DSL 1.0 Release Notes
Gradle Kotlin DSL 1.0 brings Kotlin 1.3.0, performance improvements, script compilation build cache, API/DSL refinements and fixes.
In order to benefit from the best user experience, please update IntelliJ IDEA to 2018.3, Android Studio to 3.2 and their Kotlin Plugin to the latest 1.3.
Thanks to a great help from the community, the Gradle User Manual now contains samples for both the Groovy and Kotlin DSLs. This is now the best place to find information on how to use the Gradle Kotlin DSL as it covers all Gradle features from using plugins to customizing the dependency resolution behavior.
A new user manual chapter dedicated to the Gradle Kotlin DSL has also been added.
The Gradle Plugin Portal now displays Kotlin DSL snippets for easy copy and paste.
This release contains potential breaking changes, see below.
v1.0.3 is included in Gradle 5.0 RC3.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.0-rc-3 --distribution-type all
Updates since v1.0.2 (Gradle 5.0 RC2)
-
Let
getting
property delegate usegetByName()
instead ofnamed()
(#1247) -
Let
creating
property delegate usecreate()
instead ofregister()
(#1246)
For the complete list see the gradle/kotlin-dsl
issues for 1.0.3.
Updates since v1.0-RC14 (Gradle 5.0 RC1)
-
Let generated source code import default package types (#1205, #1239)
-
The
kotlin-dsl
plugin don't pin kotlin dependencies anymore (#1241)
For the complete list see the gradle/kotlin-dsl
issues for 1.0.2.
Updates since v1.0-RC12 (Gradle 5.0 M1)
-
Upgrade embedded Kotlin to 1.3.0 (#1197)
Please see the Kotlin 1.3 announcement, What’s New page, ChangeLog and Compatibility Guide for more information.
-
Faster script compilation (#1168, #817, #1199)
The biggest bottleneck in the Gradle Kotlin DSL was the compilation of the generated Kotlin type-safe accessors during script compilation. The most impacted use cases were first time use of a build, and, the feedback loop when making changes to the build logic, both from the command line or in the script editor.
In this release we replaced the usage of the Kotlin compiler for this particular step by generating the bytecode directly instead. The generated accessors are lean and repetitive, no need for a full-blown compiler to produce their bytecode.
The IDE experience is preserved, you can still display accessors documentation in context and navigate to their sources.
On the
gradle/kotlin-dsl
build with a dozen projects and a fair amount of custom build logic, the feedback loop on API change inbuildSrc
went from ~10s to ~6s. That's a 40% improvement.On a small Android application, here the Android Sunflower sample application, the feedback loop on API change in
buildSrc
went from ~7s down to ~4.5s. That's a 40% improvement too.The effect is even more drastic on complex builds. On the
gradle/gradle
build that has almost a hundred projects and a fairly complex build logic, the feedback loop on API change inbuildSrc
went from ~1 minute down to ~25s. That's a 60% improvement.That change has about the same effect on the clean checkout use case, and, improves the first time use of a small build by ~20%. For all use cases, the larger the build, bigger is the impact.
-
Fix Gradle daemon meta space leak caused by
kotlin-dsl
plugin (#1188)A permanent generation / meta space memory leak was introduced in 1.0 RC1 causing the Gradle daemon to consume spurious memory and eventually fail with
OutOfMemoryError
. This is now fixed. See the linked issue for the tasty details. -
IDE script resolver skip buildSrc verification tasks (#1174)
In order to shorten the feedback loop in the
.gradle.kts
editor, the script dependencies resolver now skips all verification tasks from thebuildSrc
build if present. -
Generate compilable container elements accessors for element with type in the default package (#1158, #1162, #1164)
Previous release introduced type-safe accessors for elements of containers (e.g.
tasks.compileJava { }
) but they were not compilable and caused builds to fail when the element type was from the default package. This is now fixed.
For the complete list see the gradle/kotlin-dsl
issues for 1.0-RC14.
Updates since v1.0-RC6 (Gradle 4.10.2)
-
Upgrade embedded Kotlin to 1.3.0-RC2 (#1149, #1005, #1112, #1125, #1132)
Note that Gradle Kotlin DSL 1.0 will ship with Kotlin 1.3 GA.
-
Script compilation build cache is now enabled alongside the Gradle Build Cache (#1152)
If you enable the Gradle Build Cache then the Gradle Kotlin DSL will store and fetch the outputs of script compilation, avoiding the expensive work of recompiling them.
-
Accessors for plugins present in
buildSrc
(#1156)You can now refer statically to plugins declared in
buildSrc
. Instead of:plugins { id("my.buildSrc.plugin.ID") }
you can now write:
plugins { my.buildSrc.plugin.ID }
-
Accessors for elements of collections (#879, #1041)
It is now possible to refer to elements of collections available at build script body compilation time via type-safe accessors. This is applied to
configurations
,tasks
and all Gradle extensions that are collections such assourceSets
. Fortasks
, it means that instead of writing:plugins { java } tasks { named<Test>("test") { testLogging.showStacktraces = true } }
you can now write:
plugins { java } tasks { test { testLogging.showStacktraces = true } }
-
Accessors for artifact configurations in
configurations {}
(#1118, #1129)Accessors for artifact configurations were missing in the
configurations {}
block. This has been fixed the same way as for all collections, see above. Instead of:plugins { java } configurations { named("implementation") { exclude(group = "org.foo") } }
you can now write:
plugins { java } configurations { implementation { exclude(group = "org.foo") } }
-
Refine dependency constraints DSL (#710, #1091)
Accessors for artifact configurations were missing in the
dependencies { constraints {} }
block. This has been fixed. Instead of:plugins { java } dependencies { constraints { add("implementation", "com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
you can now write:
plugins { java } depen...
1.0.2
Gradle Kotlin DSL 1.0 Release Notes
Gradle Kotlin DSL 1.0 brings Kotlin 1.3.0, performance improvements, script compilation build cache, API/DSL refinements and fixes.
In order to benefit from the best user experience, please update IntelliJ IDEA to 2018.3, Android Studio to 3.2 and their Kotlin Plugin to the latest 1.3.
Thanks to a great help from the community, the Gradle User Manual now contains samples for both the Groovy and Kotlin DSLs. This is now the best place to find information on how to use the Gradle Kotlin DSL as it covers all Gradle features from using plugins to customizing the dependency resolution behavior.
A new user manual chapter dedicated to the Gradle Kotlin DSL has also been added.
The Gradle Plugin Portal now displays Kotlin DSL snippets for easy copy and paste.
This release contains potential breaking changes, see below.
v1.0.2 is included in Gradle 5.0 RC2.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.0-rc-2 --distribution-type all
Updates since v1.0-RC14 (Gradle 5.0 RC1)
-
Let generated source code import default package types (#1205, #1239)
-
The
kotlin-dsl
plugin don't pin kotlin dependencies anymore (#1241)
For the complete list see the gradle/kotlin-dsl
issues for 1.0.2.
Updates since v1.0-RC12 (Gradle 5.0 M1)
-
Upgrade embedded Kotlin to 1.3.0 (#1197)
Please see the Kotlin 1.3 announcement, What’s New page, ChangeLog and Compatibility Guide for more information.
-
Faster script compilation (#1168, #817, #1199)
The biggest bottleneck in the Gradle Kotlin DSL was the compilation of the generated Kotlin type-safe accessors during script compilation. The most impacted use cases were first time use of a build, and, the feedback loop when making changes to the build logic, both from the command line or in the script editor.
In this release we replaced the usage of the Kotlin compiler for this particular step by generating the bytecode directly instead. The generated accessors are lean and repetitive, no need for a full-blown compiler to produce their bytecode.
The IDE experience is preserved, you can still display accessors documentation in context and navigate to their sources.
On the
gradle/kotlin-dsl
build with a dozen projects and a fair amount of custom build logic, the feedback loop on API change inbuildSrc
went from ~10s to ~6s. That's a 40% improvement.On a small Android application, here the Android Sunflower sample application, the feedback loop on API change in
buildSrc
went from ~7s down to ~4.5s. That's a 40% improvement too.The effect is even more drastic on complex builds. On the
gradle/gradle
build that has almost a hundred projects and a fairly complex build logic, the feedback loop on API change inbuildSrc
went from ~1 minute down to ~25s. That's a 60% improvement.That change has about the same effect on the clean checkout use case, and, improves the first time use of a small build by ~20%. For all use cases, the larger the build, bigger is the impact.
-
Fix Gradle daemon meta space leak caused by
kotlin-dsl
plugin (#1188)A permanent generation / meta space memory leak was introduced in 1.0 RC1 causing the Gradle daemon to consume spurious memory and eventually fail with
OutOfMemoryError
. This is now fixed. See the linked issue for the tasty details. -
IDE script resolver skip buildSrc verification tasks (#1174)
In order to shorten the feedback loop in the
.gradle.kts
editor, the script dependencies resolver now skips all verification tasks from thebuildSrc
build if present. -
Generate compilable container elements accessors for element with type in the default package (#1158, #1162, #1164)
Previous release introduced type-safe accessors for elements of containers (e.g.
tasks.compileJava { }
) but they were not compilable and caused builds to fail when the element type was from the default package. This is now fixed.
For the complete list see the gradle/kotlin-dsl
issues for 1.0-RC14.
Updates since v1.0-RC6 (Gradle 4.10.2)
-
Upgrade embedded Kotlin to 1.3.0-RC2 (#1149, #1005, #1112, #1125, #1132)
Note that Gradle Kotlin DSL 1.0 will ship with Kotlin 1.3 GA.
-
Script compilation build cache is now enabled alongside the Gradle Build Cache (#1152)
If you enable the Gradle Build Cache then the Gradle Kotlin DSL will store and fetch the outputs of script compilation, avoiding the expensive work of recompiling them.
-
Accessors for plugins present in
buildSrc
(#1156)You can now refer statically to plugins declared in
buildSrc
. Instead of:plugins { id("my.buildSrc.plugin.ID") }
you can now write:
plugins { my.buildSrc.plugin.ID }
-
Accessors for elements of collections (#879, #1041)
It is now possible to refer to elements of collections available at build script body compilation time via type-safe accessors. This is applied to
configurations
,tasks
and all Gradle extensions that are collections such assourceSets
. Fortasks
, it means that instead of writing:plugins { java } tasks { named<Test>("test") { testLogging.showStacktraces = true } }
you can now write:
plugins { java } tasks { test { testLogging.showStacktraces = true } }
-
Accessors for artifact configurations in
configurations {}
(#1118, #1129)Accessors for artifact configurations were missing in the
configurations {}
block. This has been fixed the same way as for all collections, see above. Instead of:plugins { java } configurations { named("implementation") { exclude(group = "org.foo") } }
you can now write:
plugins { java } configurations { implementation { exclude(group = "org.foo") } }
-
Refine dependency constraints DSL (#710, #1091)
Accessors for artifact configurations were missing in the
dependencies { constraints {} }
block. This has been fixed. Instead of:plugins { java } dependencies { constraints { add("implementation", "com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
you can now write:
plugins { java } dependencies { constraints { implementation("com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
-
Refine containers API (#1042, #1104, #1108, [#1116](https://g...
1.0-RC14
Gradle Kotlin DSL 1.0 RC14 Release Notes
Gradle Kotlin DSL 1.0 RC14 brings Kotlin 1.3.0, performance improvements, script compilation build cache, API/DSL refinements and fixes.
In order to benefit from the best user experience, please update IntelliJ IDEA to 2018.3, Android Studio to 3.2 and their Kotlin Plugin to the latest 1.3.
Thanks to a great help from the community, the Gradle User Manual now contains samples for both the Groovy and Kotlin DSLs. This is now the best place to find information on how to use the Gradle Kotlin DSL as it covers all Gradle features from using plugins to customizing the dependency resolution behavior.
A new user manual chapter dedicated to the Gradle Kotlin DSL has also been added.
The Gradle Plugin Portal now displays Kotlin DSL snippets for easy copy and paste.
This release contains potential breaking changes, see below.
v1.0-RC14 is included in Gradle 5.0 RC1.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.0-rc-1 --distribution-type all
Updates since v1.0-RC12
-
Upgrade embedded Kotlin to 1.3.0 (#1197)
Please see the Kotlin 1.3 announcement, What’s New page, ChangeLog and Compatibility Guide for more information.
-
Faster script compilation (#1168, #817, #1199)
The biggest bottleneck in the Gradle Kotlin DSL was the compilation of the generated Kotlin type-safe accessors during script compilation. The most impacted use cases were first time use of a build, and, the feedback loop when making changes to the build logic, both from the command line or in the script editor.
In this release we replaced the usage of the Kotlin compiler for this particular step by generating the bytecode directly instead. The generated accessors are lean and repetitive, no need for a full-blown compiler to produce their bytecode.
The IDE experience is preserved, you can still display accessors documentation in context and navigate to their sources.
On the
gradle/kotlin-dsl
build with a dozen projects and a fair amount of custom build logic, the feedback loop on API change inbuildSrc
went from ~10s to ~6s. That's a 40% improvement.On a small Android application, here the Android Sunflower sample application, the feedback loop on API change in
buildSrc
went from ~7s down to ~4.5s. That's a 40% improvement too.The effect is even more drastic on complex builds. On the
gradle/gradle
build that has almost a hundred projects and a fairly complex build logic, the feedback loop on API change inbuildSrc
went from ~1 minute down to ~25s. That's a 60% improvement.That change has about the same effect on the clean checkout use case, and, improves the first time use of a small build by ~20%. For all use cases, the larger the build, bigger is the impact.
-
Fix Gradle daemon meta space leak caused by
kotlin-dsl
plugin (#1188)A permanent generation / meta space memory leak was introduced in 1.0 RC1 causing the Gradle daemon to consume spurious memory and eventually fail with
OutOfMemoryError
. This is now fixed. See the linked issue for the tasty details. -
IDE script resolver skip buildSrc verification tasks (#1174)
In order to shorten the feedback loop in the
.gradle.kts
editor, the script dependencies resolver now skips all verification tasks from thebuildSrc
build if present. -
Generate compilable container elements accessors for element with type in the default package (#1158, #1162, #1164)
Previous release introduced type-safe accessors for elements of containers (e.g.
tasks.compileJava { }
) but they were not compilable and caused builds to fail when the element type was from the default package. This is now fixed.
For the complete list see the gradle/kotlin-dsl
issues for 1.0-RC14.
Updates since v1.0-RC6
-
Upgrade embedded Kotlin to 1.3.0-RC2 (#1149, #1005, #1112, #1125, #1132)
Note that Gradle Kotlin DSL 1.0 will ship with Kotlin 1.3 GA.
-
Script compilation build cache is now enabled alongside the Gradle Build Cache (#1152)
If you enable the Gradle Build Cache then the Gradle Kotlin DSL will store and fetch the outputs of script compilation, avoiding the expensive work of recompiling them.
-
Accessors for plugins present in
buildSrc
(#1156)You can now refer statically to plugins declared in
buildSrc
. Instead of:plugins { id("my.buildSrc.plugin.ID") }
you can now write:
plugins { my.buildSrc.plugin.ID }
-
Accessors for elements of collections (#879, #1041)
It is now possible to refer to elements of collections available at build script body compilation time via type-safe accessors. This is applied to
configurations
,tasks
and all Gradle extensions that are collections such assourceSets
. Fortasks
, it means that instead of writing:plugins { java } tasks { named<Test>("test") { testLogging.showStacktraces = true } }
you can now write:
plugins { java } tasks { test { testLogging.showStacktraces = true } }
-
Accessors for artifact configurations in
configurations {}
(#1118, #1129)Accessors for artifact configurations were missing in the
configurations {}
block. This has been fixed the same way as for all collections, see above. Instead of:plugins { java } configurations { named("implementation") { exclude(group = "org.foo") } }
you can now write:
plugins { java } configurations { implementation { exclude(group = "org.foo") } }
-
Refine dependency constraints DSL (#710, #1091)
Accessors for artifact configurations were missing in the
dependencies { constraints {} }
block. This has been fixed. Instead of:plugins { java } dependencies { constraints { add("implementation", "com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
you can now write:
plugins { java } dependencies { constraints { implementation("com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
-
Refine containers API (#1042, #1104, #1108, #1116)
During the RC phase, several discrepancies were found in the domain object collections and containers API. Special care has been taken to iron it in this release. Please see the linked issues for more information.
-
Let the
kotlin-dsl
plugin configure precompiled script plugins support (#1135)Applying the
kotlin-dsl
plugin now also applies thekotlin-dsl-precompiled-script-plugins
plugin. See the [Gradle Kotlin DSL Pri...
1.0-RC12
Gradle Kotlin DSL 1.0 RC12 Release Notes
Gradle Kotlin DSL 1.0 RC12 brings Kotlin 1.3.0 RC2, fixes to issues identified since 1.0 RC6, API/DSL refinements and enables the script compilation build cache.
In order to benefit from the best user experience, please update IntelliJ IDEA to 2018.3 EAP, Android Studio to 3.2 and their Kotlin Plugin to the latest 1.3 EAP (1.3.0-rc-116
at the time of this writing).
Thanks to a great help from the community, the Gradle User Manual now contains samples for both the Groovy and Kotlin DSLs. This is now the best place to find information on how to use the Gradle Kotlin DSL as it covers all Gradle features from using plugins to customizing the dependency resolution behavior.
A new user manual chapter dedicated to the Gradle Kotlin DSL has also been added.
This release contains potential breaking changes, see below.
v1.0-RC12 is included in Gradle 5.0-M1.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 5.0-milestone-1 --distribution-type all
Updates since v1.0-RC6
-
Upgrade embedded Kotlin to 1.3.0-RC2 (#1149, #1005, #1112, #1125, #1132)
Note that Gradle Kotlin DSL 1.0 will ship with Kotlin 1.3 GA.
-
Script compilation build cache is now enabled alongside the Gradle Build Cache (#1152)
If you enable the Gradle Build Cache then the Gradle Kotlin DSL will store and fetch the outputs of script compilation, avoiding the expensive work of recompiling them.
-
Accessors for plugins present in
buildSrc
(#1156)You can now refer statically to plugins declared in
buildSrc
. Instead of:plugins { id("my.buildSrc.plugin.ID") }
you can now write:
plugins { my.buildSrc.plugin.ID }
-
Accessors for elements of collections (#879, #1041)
It is now possible to refer to elements of collections available at build script body compilation time via type-safe accessors. This is applied to
configurations
,tasks
and all Gradle extensions that are collections such assourceSets
. Fortasks
, it means that instead of writing:plugins { java } tasks { named<Test>("test") { testLogging.showStacktraces = true } }
you can now write:
plugins { java } tasks { test { testLogging.showStacktraces = true } }
-
Accessors for artifact configurations in
configurations {}
(#1118, #1129)Accessors for artifact configurations were missing in the
configurations {}
block. This has been fixed the same way as for all collections, see above. Instead of:plugins { java } configurations { named("implementation") { exclude(group = "org.foo") } }
you can now write:
plugins { java } configurations { implementation { exclude(group = "org.foo") } }
-
Refine dependency constraints DSL (#710, #1091)
Accessors for artifact configurations were missing in the
dependencies { constraints {} }
block. This has been fixed. Instead of:plugins { java } dependencies { constraints { add("implementation", "com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
you can now write:
plugins { java } dependencies { constraints { implementation("com.google.collections:google-collections") { version { rejectAll() } because("Google collections is superceded by Guava") } } }
-
Refine containers API (#1042, #1104, #1108, #1116)
During the RC phase, several discrepancies were found in the domain object collections and containers API. Special care has been taken to iron it in this release. Please see the linked issues for more information.
-
Let the
kotlin-dsl
plugin configure precompiled script plugins support (#1135)Applying the
kotlin-dsl
plugin now also applies thekotlin-dsl-precompiled-script-plugins
plugin. See the Gradle Kotlin DSL Primer chapter of the Gradle User Manual for more information. -
Refine IDE script dependencies resolver (#1133, #1124, #1139)
The dependencies resolver backing IDE editors for
.gradle.kts
scripts has been refined to emit warnings only when necessary and display actionable messages. Please see the linked issues for more information.
For the complete list see the gradle/kotlin-dsl
issues for 1.0-RC12.
Breaking changes
This release contains some potential breaking changes:
-
Upgrade embedded Kotlin to 1.3.0-RC2
Kotlin DSL 1.0-rc-12 ships with Kotlin 1.3 RC2 (
1.3.0-rc-116
) which is only available via thekotlin-eap
repository.
Usually, that would mean that in order to use thekotlin-dsl
plugin or the embedded Kotlin plugin version, thekotlin-eap
repository would have to be added tosettings.pluginManagement.repositories
andallprojects.repositories
. With the intent of making it easier to try, Kotlin DSL 1.0-rc-12 does it automatically for any project that includes asettings.gradle.kts
.
This behaviour will be removed once Kotlin 1.3 GA is available. -
Artifact configuration accessors are now typed
NamedDomainObjectProvider<Configuration>
Instead of simply
Configuration
. This goes in line with the fact that the Kotlin DSL sugar embrace the new configuration avoidance APIs.
Avoiding Gradle Kotlin DSL internal APIs
Use of Kotlin DSL internal APIs in plugins and build scripts has the potential to break builds when either Gradle or plugins change.
The Kotlin DSL extends the Gradle public API definition with org/gradle/kotlin/dsl/*
excluding any subpackages.
1.0-RC6
Gradle Kotlin DSL 1.0 RC6 Release Notes
Gradle Kotlin DSL 1.0 RC6 brings Kotlin 1.2.61, support for configuration avoidance, a Gradle API decorated for Kotlin, enhanced IntelliJ IDEA integration, lots of DSL polish and bug fixes.
At the same time the IntelliJ IDEA Kotlin Plugin fixed important build script editing related issues. It is recommended for everyone to upgrade to the latest and greatest.
This release contains potential breaking changes, see below.
v1.0-RC6 is included in Gradle 4.10.1.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 4.10.1 --distribution-type all
Updates since v1.0-RC3
-
Upgrade embedded Kotlin to 1.2.61 (#1059)
-
Generate compilable accessors for extension types in the default package (#807,#1060)
-
Regenerate accessors jar upon classpath changes (#1061)
-
Configuring Project fails when non-jar in build script classpath (#1021, #1039)
-
Using the
build-scan
property extension should apply the same build-scan plugin version as running with --scan (#1083, #1085, gradle/gradle#6713) -
duplicatesStrategy
property ofCopy
task cannot be set inbuildSrc
(#1070, gradle/gradle#6533) -
ScriptHandlerScope
is missing overloads for adding dependencies (#1048, #1084)
Updates since v1.0-RC1
-
Add missing specialized
withType<T>()
extensions onNamedDomainObjectCollection
(#1034, #1035) -
Let build-cache be enabled via system property instead of project property (#1032, #1036)
-
Make the build cache keys compatible with the remote build cache (#1023, #1027)
Updates since v0.18.4
-
Documentation (#665, #835, #966, #968, #988)
All public Gradle Kotlin DSL API members now have proper documentation available in the IDE and in the API reference.You might also want to check out the guide to migrating build logic from Groovy to Kotlin and other Gradle guides that now contain samples for the Gradle Kotlin DSL.
-
Script compilation build cache (#963, #978, #987)
Compiled project scripts can now be cached in a shared Gradle build cache for maximum reuse across builds. The experimental build cache integration must be explicitly enabled via theorg.gradle.kotlin.dsl.caching.buildcache
Gradle project property set totrue
. -
Script compilation now targets JVM 8 (#955, #955)
As a result, it is now possible to use libraries targeting JVM 8 in your build scripts. -
IDE integration improvements (#962, #972, #942, #464, #1004)
When editing build logic in IntelliJ IDEA, changes are now propagated between scripts and betweenbuildSrc
and scripts without having to sync the Gradle build, resulting in a much better user experience.The lifecycle of Gradle daemons spawned by IntelliJ IDEA when editing Gradle Kotlin DSL script has been revised to prevent running too many of them. Before that change and under certain circumstances, one Gradle daemon was running per open script, this is now limited, resulting in less pressure on the system and a quicker feedback.
Moreover, all usages of types relying on kotlin implementation by delegation for a Java interface now show meaningful parameter name hints instead of
p0
,p1
etc..: -
Support for configuration avoidance of named domain object containers (#123, #907, #986, #993, #994, #1000)
Gradle 4.9 introduced new APIs for declaring and configuring Gradle Tasks in build scripts and plugins that allow Gradle to avoid executing unnecessary build logic.
Gradle 4.10 makes the same API available for allNamedDomainObjectContainer
types.This release of the Gradle Kotlin DSL promotes these APIs as the preferred way of configuring container elements by
- reimplementing the
String
invoke DSL sugar plus thegetting
andcreating
delegated properties atop the new APIs ; - introducing the new
existing
andregistering
delegated properties designed specifically with configuration avoidance in mind which exposeNamedDomainObjectProvider<T>
instead of the container element type.
As an example, let's look at wiring a simple task graph using only the new configuration avoidance support.
/** * An example Gradle task. */ open class GreetingTask : DefaultTask() { val message = project.objects.property<String>() @TaskAction fun greet() = println(message.get()) } tasks { // `hello` is a `TaskProvider<GreetingTask>` val hello by registering(GreetingTask::class) { message.set("Hello!") } // `goodbye` is a `TaskProvider<GreetingTask>` val goodbye by registering(GreetingTask::class) // Every `NamedDomainObjectProvider<T>` can be lazily configured as follows goodbye { dependsOn(hello) } // Existing container elements can be lazily configured via the `String` invoke DSL "goodbye"(GreetingTask::class) { message.set("Goodbye!") } // Regular API members are also available register("chat") } // ... tasks { // Existing container elements can be lazily brought into scope val goodbye by existing "chat" { dependsOn(goodbye) } }
- reimplementing the
-
SAM conversion for Kotlin functions (#522, #960)
SAM (Single Abstract Method) conversion for Kotlin functions allows Kotlin build logic to expose and consumeorg.gradle.api.Action<T>
based APIs. Such APIs can then be used uniformly from both the Kotlin and Groovy DSLs.As an example, given the following hypothetical Kotlin function with a Java SAM parameter type:
fun kotlinFunctionWithJavaSam(action: org.gradle.api.Action<Any>) = TODO()
SAM conversion for Kotlin functions enables the following usage of the function:
kotlinFunctionWithJavaSam { // ... }
Without SAM conversion for Kotlin functions one would have to explicitly convert the passed lambda:
kotlinFunctionWithJavaSam(Action { // ... })
-
Gradle API is decorated for Kotlin (#221, #914)
The public Gradle API available ...
1.0-RC3
Gradle Kotlin DSL 1.0 RC3 Release Notes
Gradle Kotlin DSL 1.0 RC3 brings Kotlin 1.2.60, support for configuration avoidance, a Gradle API decorated for Kotlin, enhanced IntelliJ IDEA integration, lots of DSL polish and bug fixes.
At the same time the IntelliJ IDEA Kotlin Plugin fixed important build script editing related issues. It is recommended for everyone to upgrade to the latest and greatest.
This release contains potential breaking changes, see below.
v1.0-RC3 is included in Gradle 4.10 RC3.
To use it, upgrade your Gradle wrapper in the following fashion:
$ cd $YOUR_PROJECT_ROOT
$ gradle wrapper --gradle-version 4.10-rc-3 --distribution-type all
Updates since v1.0-RC1
-
Add missing specialized
withType<T>()
extensions onNamedDomainObjectCollection
(#1034, #1035) -
Let build-cache be enabled via system property instead of project property (#1032, #1036)
-
Make the build cache keys compatible with the remote build cache (#1023, #1027)
Updates since v0.18.4
-
Documentation (#665, #835, #966, #968, #988)
All public Gradle Kotlin DSL API members now have proper documentation available in the IDE and in the API reference.You might also want to check out the guide to migrating build logic from Groovy to Kotlin and other Gradle guides that now contain samples for the Gradle Kotlin DSL.
-
Script compilation build cache (#963, #978, #987)
Compiled project scripts can now be cached in a shared Gradle build cache for maximum reuse across builds. The experimental build cache integration must be explicitly enabled via theorg.gradle.kotlin.dsl.caching.buildcache
Gradle project property set totrue
. -
Script compilation now targets JVM 8 (#955, #955)
As a result, it is now possible to use libraries targeting JVM 8 in your build scripts. -
IDE integration improvements (#962, #972, #942, #464, #1004)
When editing build logic in IntelliJ IDEA, changes are now propagated between scripts and betweenbuildSrc
and scripts without having to sync the Gradle build, resulting in a much better user experience.The lifecycle of Gradle daemons spawned by IntelliJ IDEA when editing Gradle Kotlin DSL script has been revised to prevent running too many of them. Before that change and under certain circumstances, one Gradle daemon was running per open script, this is now limited, resulting in less pressure on the system and a quicker feedback.
Moreover, all usages of types relying on kotlin implementation by delegation for a Java interface now show meaningful parameter name hints instead of
p0
,p1
etc..: -
Support for configuration avoidance of named domain object containers (#123, #907, #986, #993, #994, #1000)
Gradle 4.9 introduced new APIs for declaring and configuring Gradle Tasks in build scripts and plugins that allow Gradle to avoid executing unnecessary build logic.
Gradle 4.10 makes the same API available for allNamedDomainObjectContainer
types.This release of the Gradle Kotlin DSL promotes these APIs as the preferred way of configuring container elements by
- reimplementing the
String
invoke DSL sugar plus thegetting
andcreating
delegated properties atop the new APIs ; - introducing the new
existing
andregistering
delegated properties designed specifically with configuration avoidance in mind which exposeNamedDomainObjectProvider<T>
instead of the container element type.
As an example, let's look at wiring a simple task graph using only the new configuration avoidance support.
/** * An example Gradle task. */ open class GreetingTask : DefaultTask() { val message = project.objects.property<String>() @TaskAction fun greet() = println(message.get()) } tasks { // `hello` is a `TaskProvider<GreetingTask>` val hello by registering(GreetingTask::class) { message.set("Hello!") } // `goodbye` is a `TaskProvider<GreetingTask>` val goodbye by registering(GreetingTask::class) // Every `NamedDomainObjectProvider<T>` can be lazily configured as follows goodbye { dependsOn(hello) } // Existing container elements can be lazily configured via the `String` invoke DSL "goodbye"(GreetingTask::class) { message.set("Goodbye!") } // Regular API members are also available register("chat") } // ... tasks { // Existing container elements can be lazily brought into scope val goodbye by existing "chat" { dependsOn(goodbye) } }
- reimplementing the
-
SAM conversion for Kotlin functions (#522, #960)
SAM (Single Abstract Method) conversion for Kotlin functions allows Kotlin build logic to expose and consumeorg.gradle.api.Action<T>
based APIs. Such APIs can then be used uniformly from both the Kotlin and Groovy DSLs.As an example, given the following hypothetical Kotlin function with a Java SAM parameter type:
fun kotlinFunctionWithJavaSam(action: org.gradle.api.Action<Any>) = TODO()
SAM conversion for Kotlin functions enables the following usage of the function:
kotlinFunctionWithJavaSam { // ... }
Without SAM conversion for Kotlin functions one would have to explicitly convert the passed lambda:
kotlinFunctionWithJavaSam(Action { // ... })
-
Gradle API is decorated for Kotlin (#221, #914)
The public Gradle API available in Gradle Kotlin DSL scripts and Kotlin sources of projects applying thekotlin-dsl
plugin is now decorated with Kotlin extensions mappingjava.lang.Class<?>
function parameters tokotlin.reflect.KClass<?>
parameters.As an example, the following settings file:
buildCache { remote(HttpBuildCache::class.java) { url = uri("http://example.com/cache") } }
can now be written omitting
.java
:buildCache { remote(HttpBuildCache::class) { url = uri("http://example.com/cache") } }
For the complete list see the gradle/kotlin-dsl
issues for 1.0-RC1, 1.0-RC2 and 1.0-RC3.
Breaking changes
This release contains some potential breaking changes:
-
java.sourceSets
now issourceSets
The source set container can now be accessed usingproject.sourceSets
, or justsourceSets
. Previously it was located atproject.java.sourceSets
, or justjava.sourceSets
. -
Container
String
invoke now isnamed()
instead ofmaybeCreate()
This change in behaviour can cause builds to fail withorg.gradle.api.UnknownDomainObjectException
. The fix is to explicitly callcreate
or preferablyregister
.For a concrete example, the following script which, before this change, ...