Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gradle): Add basic Gradle Kotlin DSL support #4086

Merged
merged 2 commits into from
Aug 4, 2019

Conversation

ikesyo
Copy link
Collaborator

@ikesyo ikesyo commented Jul 14, 2019

This partially implements #3054.

  • *.gradle.kts and buildSrc/**/* files are now recognized
  • Kotlin's named arguments are supported, such as: implementation(group = "...", name = "...", version = "...")

@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch 4 times, most recently from f684ca7 to 68e53a2 Compare July 14, 2019 13:04
@rarkins rarkins requested a review from corecanarias July 14, 2019 20:32
@rarkins
Copy link
Collaborator

rarkins commented Jul 14, 2019

Thanks @ikesyo ! Hoping that @corecanarias has some spare time to review this soon

@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch from 68e53a2 to aeb4bc0 Compare July 15, 2019 14:51
@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch from dfea6a4 to af9f34f Compare July 23, 2019 00:16
@ikesyo
Copy link
Collaborator Author

ikesyo commented Jul 23, 2019

Hi @corecanarias @rarkins, is there any chance to get this reviewed?

@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch 5 times, most recently from 1c52adf to 6d2bf98 Compare July 27, 2019 11:40
@rarkins
Copy link
Collaborator

rarkins commented Jul 29, 2019

@ikesyo thank you for this PR! I think @corecanarias is busy lately, but I'll try to take a look. Could you fix the conflicted file?

@ikesyo
Copy link
Collaborator Author

ikesyo commented Jul 29, 2019

Could you fix the conflicted file?

Yes of course!

@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch 2 times, most recently from 7d64f88 to 1f235b7 Compare July 29, 2019 08:16
@ikesyo
Copy link
Collaborator Author

ikesyo commented Jul 29, 2019

@rarkins I've resolved the conflicts.

fileMatch: [
'\\.gradle(\\.kts)?$',
'(^|/)gradle.properties$',
'(^|/)buildSrc/.*',
Copy link
Collaborator

@rarkins rarkins Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is buildSrc needed in the fileMatch?

Copy link
Collaborator Author

@ikesyo ikesyo Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entry is needed to detect/collect/update dependencies/variables defined in source files within buildSrc.

As @jcornaz said in #3054, it is becoming popular that defining dependencies/versions in a Kotlin (or Java) source files under buildSrc.

The other point to keep in mind is that (although not specific to the Kotlin DSL) storing version numbers in Java or Kotlin files in the buildSrc directory is quite popular among Kotlin DSL users (because it gives us good auto-completion and type-safety in build scripts)

For example:

Even though I don't handle contents such as:

object Versions {
    val support_lib = "27.0.2"
    val retrofit = "2.3.0"
    val rxjava = "2.1.9"
}

object Libs {
    val support_annotations = "com.android.support:support-annotations:${Versions.support_lib}"
    val support_appcompat_v7 = "com.android.support:appcompat-v7:${Versions.support_lib}"
    val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
    val retrofit_rxjava_adapter = "com.squareup.retrofit2:adapter-rxjava2:${Versions.retrofit}"
    val rxjava = "io.reactivex.rxjava2:rxjava:${Versions.rxjava}"
}

but this PR should work against more simple cases (no enclosing types $Versions.fooVariable) such as:

object Libs {
    private val supportLibVersion = "27.0.2"
    private val retrofitVersion = "2.3.0"
    private val rxjavaVersion = "2.1.9"

    val support_annotations = "com.android.support:support-annotations:${supportLibVersion}"
    val support_appcompat_v7 = "com.android.support:appcompat-v7:${supportLibVersion}"
    val retrofit = "com.squareup.retrofit2:retrofit:${retrofitVersion}"
    val retrofit_rxjava_adapter = "com.squareup.retrofit2:adapter-rxjava2:${retrofitVersion}"
    val rxjava = "io.reactivex.rxjava2:rxjava:${rxjavaVersion}"
}

Copy link
Collaborator Author

@ikesyo ikesyo Jul 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reconsidered this. As you said in #3054 (comment), not adding buildSrc to the fileMatch and instead letting users add exact wanted files by themselves will be good (at least for now) as a first step.

Users extend fileMatch for any we miss. These would probably not be build.gradle files but more like gradle.settings files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rarkins I've just omitted the entry.

@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch 5 times, most recently from a225fc3 to 0ee9710 Compare August 3, 2019 00:09
@ikesyo ikesyo force-pushed the gradle-kotlin-dsl branch from 0ee9710 to 55389ff Compare August 3, 2019 09:29
Copy link
Contributor

@corecanarias corecanarias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took so long :/

@rarkins rarkins merged commit 9b2f457 into renovatebot:master Aug 4, 2019
@rarkins
Copy link
Collaborator

rarkins commented Aug 4, 2019

Thanks @ikesyo for the feature and @corecanarias for the review!

@renovate-bot
Copy link
Collaborator

🎉 This PR is included in version 19.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ikesyo ikesyo deleted the gradle-kotlin-dsl branch August 4, 2019 12:09
@ikesyo ikesyo mentioned this pull request Sep 1, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants