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

Sample plugin showing custom DSL #1081

Open
ryantheleach opened this issue Aug 29, 2018 · 4 comments
Open

Sample plugin showing custom DSL #1081

ryantheleach opened this issue Aug 29, 2018 · 4 comments
Labels
a:feature help wanted issues good for an external contributor to pick up in:kotlin-dsl-samples re:documentation

Comments

@ryantheleach
Copy link

It would be great to see a plugin that provides a custom DSL, that matches kotlin-dsl styles for configuring tasks using custom functions.

If it's already in the samples, it's not clear from the sample readme where it is.

@StefMa
Copy link
Contributor

StefMa commented Aug 29, 2018

Sry but I don't get your question 🙃
You can "get" a Task like tasks.withType<TaskType> { // set it up here }.
Does that answer you question?

@ryantheleach
Copy link
Author

@StefMa e.g. https://github.com/gradle/kotlin-dsl/blob/master/build.gradle.kts#L110-L140

Shows the build.gradle of this project, using the idea plugin + configuration.

It has several 'type safe kotlin builders / dsl's'

But attempting to make the same in a project extension hasn't worked well for me. Seeing if there are any utilities, or if it's all manual, or a basic example of how to do that, would be excellent in order to make the plugin I plan on publishing feel like a native kotlin-dsl plugin.

@StefMa
Copy link
Contributor

StefMa commented Aug 29, 2018

Ok, understood.
Maybe you can read this article which explains the basics about the Kotlin-DSL (from user perspective).

But you are talking about of having your own plugin (or plugin extension).
You don't have to do anything special. The "nice dsl" will be created by the Gradle/Kotlin-DSL themself.
You only have to create you extension like you have done it in the "old Groovy" days.
As long as your "consumer" apply you plugin over the plugins {} block the DSL will be created for you.

But the way:
This is not a special kotlin-dsl question. Such things should be better posted in the gradle forum.

@ryantheleach
Copy link
Author

You only have to create you extension like you have done it in the "old Groovy" days.

I've been avoiding gradle due to groovy, this is the first time I've attempted to make my own plugins (and write Kotlin), most of the examples have been super helpful when combined with the gradle docs. Between my limited Scala knowledge, Java 8 experience, and C#, I've been able to mostly make heads and tails of Kotlin by referring to the documentation.

You don't have to do anything special. The "nice dsl" will be created by the Gradle/Kotlin-DSL themself.

From what? The few attempts I've made havn't had that nice syntax apply, which is why I've asked that it be a sample, so others can benefit. Even if the sample shows that you don't need to write the builders and glue code yourself, because currently that's the idea that I had, if you write a plugin in Kotlin Script, that you had to do that yourself (as opposed to writing it in groovy, where it would be generated).

(I'll push to my repo and show you when I have access to my changes next (I'm not on that machine currently))

@eskatos eskatos added in:kotlin-dsl-samples a:feature re:documentation help wanted issues good for an external contributor to pick up labels Nov 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a:feature help wanted issues good for an external contributor to pick up in:kotlin-dsl-samples re:documentation
Projects
None yet
Development

No branches or pull requests

3 participants