How to get --tests command params in plugin?

I’m writing a plugin and want to get some command line params starting with “–”, e.g, getting ‘*SomeTest’ from ‘gradle --tests *SomeTest’ command.

How can I achieve this goal?

Please help me

Support for custom command line arguments is not a public feature of the Gradle API. There exists an internal annotation named Option that could be used (see Gradle source for usage examples).

However, since it is an internal API it is subject to change at any point and may cause you issues when changing Gradle versions.
Alternatively, you can use -Pproperty=value and reference that property in various ways. There is some information about properties in the userguide and DSL reference/javadoc. One of the nicer things about properties is that they can be set in more than one way (commandline, project’s gradle.properties, user’s gradle.properties), making them a bit more flexible.

See also, this conversation.

Thanks a lot!

You save my day!

Hi Chis, I have encountered a new problem. When I start a build with BuildLauncher and ‘–tests’ arguments, I got the follow error:

Unknown command-line option '--tests'.
Either it is not a valid build option or it is not supported in the target Gradle version.
Not all of the Gradle command line options are supported build arguments.
Examples of supported build arguments: '--info', '-u', '-p'.
Examples of unsupported build options: '--daemon', '-?', '-v'.
Please find more information in the javadoc for the BuildLauncher class.

How can I turn on allowUnknownOptions in build started by BuildLauncher ?

Thank you very much.