See instructions below in order to set up your dev environment to benefit from the available IDE support.
The Gradle projects in this directory demonstrate typical use cases with and features available in the Gradle Kotlin DSL. They include:
ant
: demonstrates how to use Ant from Gradle via the Ant Groovy Builderbuild-cache
: demonstrates how to configure the Gradle build cachebuild-scan
: demonstrates how to apply and configure theorg.gradle.build-scan
pluginbuildSrc-plugin
: demonstrates how to use thekotlin-dsl
andjava-gradle-plugin
plugins together inbuildSrc
code-quality
: demonstrates how to configure Gradle code quality pluginscomposite-builds
: demonstrates how to use Composite Buildscopy
: demonstrates typed task declarations, and configuration of a GradleCopySpec
domain-objects
: demonstrates how to create and configure aNamedDomainObjectContainer
from a Kotlin build script.extra-properties
: demonstrates the use ofextra
properties (equivalent of theext
properties found in Gradle Script Groovy)gradle-plugin
: demonstrates a Gradle plugin implemented in Kotlin and taking advantage of thekotlin-dsl
plugingroovy-interop
: demonstrates how to interact with Groovy code from Kotlinhello-android
: demonstrates a Kotlin-based Gradle build script for a Kotlin-based Android projecthello-coroutines
: demonstrates how to enable experimental support for coroutines in Kotlinhello-js
: demonstrates a Kotlin-based Gradle build script for a project that is itself written in Kotlin and targets JavaScripthello-kapt
: demonstrates a Kotlin-based Gradle build script for a project that is itself written in Kotlin and useskapt
(Kotlin Annotation Processing Tool)hello-kotlin
: demonstrates a Kotlin-based Gradle build script for a project that is itself written in Kotlinhello-world
: demonstrates plugin application and configuration, dependency management, JUnit testingkotlin-friendly-groovy-plugin
: demonstrates a Groovy Gradle plugin and its use from Kotlin-based build scriptsmaven-plugin
: demonstrates how to configure the Gradlemaven
pluginmaven-publish
: demonstrates how to configure the Gradlemaven-publish
pluginmodel-rules
: demonstrates the use of model rulesmodularity
: demonstrates the use ofapply(from = "")
to modularize build scriptsmulti-kotlin-project
: demonstrates a multi-project build comprising two Kotlin based projectsmulti-kotlin-project-config-injection
: demonstrates a multi-project build comprising two Kotlin based projects in which allKotlinCompile
tasks belonging to the subprojects are configured by the root projectmulti-kotlin-project-with-buildSrc
: demonstrates a multi-project build comprising two Kotlin based projects with custom build logic inbuildSrc
multi-project-with-buildSrc
: demonstrates a multi-project build with custom build logic inbuildSrc
, including a custom taskprecompiled-script-plugin
: demonstrates a Gradle plugin implemented as a precompiled scriptproject-properties
: demonstrates project property access via delegated propertiesproject-with-buildSrc
: demonstrates a single-project build with custom build logic inbuildSrc
provider-properties
: demonstrates usage of lazily evaluated properties to map extension properties to task propertiessource-control
: demonstrates how to use external source dependenciestask-dependencies
: demonstrates explicit configuration of task dependenciestestkit
: demonstrates how to test a Gradle plugin written in Kotlin using TestKit
Note: Currently, these instructions only address working with IntelliJ IDEA. In the future, they'll be expanded to include working with Eclipse.
Version 2017.3.3 or better is required, and can be downloaded from https://www.jetbrains.com/idea.
Note: the specific version of the Kotlin plugin matters.
All the samples should work against the latest Kotlin plugin, 1.2.20 at the time of this writing, from the Stable channel accessible via the Tools > Kotlin > Configure Kotlin Plugin Updates action.
If you have not already done so, clone the kotlin-dsl repository:
git clone [email protected]:gradle/kotlin-dsl.git # ($REPO_ROOT)
Note: The remainder of these instructions focus on the hello-world
sample project, but will work equally well for any of the other samples.
In IDEA, go to File->Open...
and navigate to $REPO_ROOT/samples/hello-world
.
When prompted, choose "Use default Gradle wrapper".
The project should import without errors.
You're now ready to explore what's possible with the Gradle Kotlin DSL in IDEA. Generally speaking, things should "just work", as they would in the context of any other Java or Kotlin code you would write in IDEA.
Start by opening build.gradle.kts
.
Note: The very first time you do, IDEA might fail to recognise the classpath of the script, if that happens, simply restart IDEA. This is a known issue that will be fixed soon.
Continue with any or all of the following:
You should notice that normal Kotlin syntax highlighting works throughout the file.
Try clicking on any type or function in the script, and hit F1
(or possibly CTRL-J
, dependending on which IDEA key mapping you use). Notice how you're presented with a quick documentation pop-up complete with that element's Javadoc / KDoc.
Again, try clicking on any type or function in the script and hit CMD-B
. Notice that you're taken directly to the source for that element.
Try using CTRL-SPACE
at various sites in the script, and notice that you're provided with complete content assist regarding what's available at that site.
Most any refactoring action that is possible in a Kotlin file should also work in a Kotlin-based Gradle build script. Explore!
See the latest release notes for further details on current features and limitations.