Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Latest commit

 

History

History
112 lines (75 loc) · 7.89 KB

README.md

File metadata and controls

112 lines (75 loc) · 7.89 KB

Sample Kotlin-based Gradle build scripts

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:

Set up dev environment

Note: Currently, these instructions only address working with IntelliJ IDEA. In the future, they'll be expanded to include working with Eclipse.

Install IntelliJ IDEA

Version 2017.3.3 or better is required, and can be downloaded from https://www.jetbrains.com/idea.

Install IDEA Kotlin Plugin

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.

Set up a sample project

Clone the Gradle Kotlin DSL repository

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.

Import the sample project into IDEA

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.

Explore available IDE support

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:

Syntax highlighting

You should notice that normal Kotlin syntax highlighting works throughout the file.

Quick documentation

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.

Navigation to source

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.

Auto-completion / content assist

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.

Refactoring

Most any refactoring action that is possible in a Kotlin file should also work in a Kotlin-based Gradle build script. Explore!

See also

See the latest release notes for further details on current features and limitations.