is there any way to use the ad hoc tasks API to ad...
# community-support
t
is there any way to use the ad hoc tasks API to add a command line
@Option
to a task? My use-case is in an Android project. It has tasks like
testDebugUnitTest
and
testReleaseUnitTest
, as well as a lifecycle task
test
that depends on each of those two variant-specific Test tasks. I would love to add a
--tests
option to this preexisting (from another plugin, I do not control it)
test
lifecycle task. I've tried this, but it doesn't work:
Copy code
project.tasks.named { it == "test" }.configureEach {
  inputs
    .property("tests", "") // passing no value as a test
    .optional(true)
}
I still get
> Unknown command-line option '--tests'.
I suspect this just isn't possible
e
I thought there was an issue about this but I can't find it
👍 1
t
alternatively, the perennial idea of "replacing a task" would help here
b
It's not as nice a a command line options, but what you can do is define a project property that you can pass via -P. The benefit of this is that you can call a lifecycle task but still have another task in the graph evaluate the property.
This is the major downside with
@Option
. It only works if the task defining the option is the one you requested.
1
Test
used to have some magic to make it possible to just pass
--test
and it would figure out the right thing to do. But since recently you will get failures saying the filter didn't match any tests which is a huge usability problem IMHO.
t
I have a working proof of concept intended for Android projects that parses the command line and injects the tests option via extra properties (IP safe). It configures test tasks directly with
task.setTestNameIncludePatterns(/* value from extra properties */)
. Maybe too clever? It works though
b
if it works, it works 🤷‍♂️
🤘 1
t
here's the source code for my new (unpublished) Gradle plugin for Android, "dedebug" (de-debug, removing the debug build type from Android libraries). Also handles this
--tests
case, which is why I thought it interesting enough to wrap up in a plugin https://github.com/autonomousapps/dedebug
👍 1