Gradle: @Option is not used if the task name is not explicitly listed on the command line

Created on 15 May 2017  路  3Comments  路  Source: gradle/gradle

When we run a task and we specify an option --like-this foo (using the @Option annotation), it would work if the task is explicitly mentioned as part of the command, but fail if the task is added to the task graph as dependency.

See https://discuss.gradle.org/t/options-for-a-dependent-task/22275

Expected Behavior

Any tasks using an --option should be able to pick the value if the option was specified on the command line.

Current Behavior

Only tasks explicitly mentioned on the command line can recognize the option. This is especially confusing when the options ave defaults (i.e. gradle myTask --my-option foo works fine; gradle build --my-option foo still runs, but my-option is silently ignored )

Context

I have got a plugin that automatically creates a task corresponding to any code coverage report to upload it to an online service. There is an aggregator task depending on all upload tasks, that allows us to upload the coverage of integration and unit tests with one command. The online service requires a project token that can be specified as part of the environment or passed on the command line.

In the case of the project token defined in environment, the aggregator task works fine. If we try to specify the token on the command line, it fails because the aggregated tasks do not receive the token.

For practical example, see here:
https://github.com/ddimtirov/codacy-gradle-plugin#usage

bug contributor console stale

Most helpful comment

Just ran into this with --fail-fast with check

All 3 comments

Just ran into this with --fail-fast with check

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.

Was this page helpful?
0 / 5 - 0 ratings