Last active
October 23, 2018 07:42
-
-
Save nekocode/c40e1ac5fad1770d73c0598eb6b6e3db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.gradle.util.NameMatcher | |
| def isTaskSelected(String... taskNames) { | |
| def matcher = new NameMatcher() | |
| def nameList = Arrays.asList(taskNames) | |
| def requestedTaskNames = gradle.startParameter.taskNames | |
| for (def requestedTaskName : requestedTaskNames) { | |
| if (matcher.find(requestedTaskName, nameList) != null) { | |
| return true | |
| } | |
| } | |
| return false | |
| } | |
| // Example: | |
| isTaskSelected(":app:assembleRelease", "assembleRelease") | |
| // Note that the result is not necessarily accurate!!! | |
| // More information about the NameMatcher: | |
| // https://github.com/gradle/gradle/blob/master/subprojects/core/src/test/groovy/org/gradle/util/NameMatcherTest.java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.gradle.api.internal.GradleInternal | |
| import org.gradle.execution.commandline.CommandLineTaskParser | |
| import org.gradle.execution.TaskSelector | |
| project.gradle.taskGraph.whenReady { | |
| def parser = ((GradleInternal) project.gradle).getServices().get(CommandLineTaskParser) | |
| final List<TaskSelector.TaskSelection> selections = new ArrayList<>() | |
| for (def taskRequest : project.gradle.startParameter.taskRequests) { | |
| selections.addAll(parser.parseTasks(taskRequest)) | |
| } | |
| // Put your logic here, for example: | |
| for (def selection : selections) { | |
| if (selection.taskName == ":example:assembleRelease") { | |
| // TODO | |
| } | |
| } | |
| } | |
| // This result is accurate. But you can't use it in the configuration phase. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment