-
Notifications
You must be signed in to change notification settings - Fork 156
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
Add meta tasks for Android variants #183
Add meta tasks for Android variants #183
Conversation
Now plugin adds variant specific tasks that depends on variant sourceSets check tasks. Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
@tasomaniac may you also take a look on this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Only have a small comment. Would be good to add tests for this. Should we craete an issue and link here?
@@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |||
|
|||
## [Unreleased] | |||
### Added | |||
- ? | |||
- Meta tasks to run check or format on all sources in android variant. (#170) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👌
multiplatformTargetName: String? = null | ||
): Task { | ||
val taskName = "ktlint${variantName.capitalize()}${multiplatformTargetName?.capitalize() ?: ""}Check" | ||
return tasks.findByName(taskName) ?: task(taskName).apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead can you use tasks.maybeCreate()
that conditionally creates a task and returns the already available task if so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, all of these options are eagerly evaluated. I'd love if there was a way to lazily instantiate this task.
Don't worry about that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure actually. findByName is also not lazy. maybeCreate
looks like a drop-in replacement of what you do here.
At the end it is not crucial. Either is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, this can addressed in next PR with task configuration avoidance. For now, I changed it to maybeCreate()
private fun setCheckTaskDependsOnKtlintCheckTask(project: Project, ktlintCheck: Task) { | ||
project.tasks.findByName("check")?.dependsOn(ktlintCheck) | ||
} | ||
|
||
/* | ||
* Helper functions used until Gradle Script Kotlin solidifies it's plugin API. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a line of documentation for all lower lines, so this newline gap was intentional.
One concern I want to bring up is the potential for accidental task name collisions. If there are, please figure out how to prevent these task name collisions. |
I don't see any problems. It will bring back the old functionality of the tasks back. The breaking change would be that the type of the tasks has changed together with the report file destinations. We are using that actually but I will make the necessary changes to support the new structure. I guess the |
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
I agree with @tasomaniac that there is no problem with this. |
Okay, if you are both unconcerned, then go for it if this is ready to go. |
Nice. Are you guys going to release a new version now or does it need more stuff in? |
@tasomaniac As next release will anyway break api - I also want to bump minimal supported Gradle version to |
Hey about the task configuration avoidance: there is a way to make it available in a backward compatible way. I found this example from official docs: https://github.com/melix/jmh-gradle-plugin/blob/a034aa88805b7a06fa9c5a825d573554b2aa23e2/src/main/groovy/me/champeau/gradle/JMHPlugin.groovy#L289-L296 Especially with Kotlin extension functions, this can be done in a very nice way. |
This PR adds android variants meta tasks, that trigger tasks for all source sets in given variant.
For example running
ktlintKellerbierDebugCheck
meta task triggers following tasks:Also added limited support for android projects in new Kotlin multiplatform plugin:
Currently variant task name is inconsistent with source sets tasks names, but that will be addressed in #182 issue.
Closes #170.