# Using @Option outside tasks

**URL:** <https://discuss.gradle.org/t/using-option-outside-tasks/12290>\
**Category:** Help/Discuss\
**Created:** [October 19, 2015, 3:31pm UTC](https://discuss.gradle.org/t/using-option-outside-tasks/12290 "2015-10-19T15:31:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![moley](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@moley](https://discuss.gradle.org/u/moley)\
**Post date:** [October 19, 2015, 3:31pm UTC](https://discuss.gradle.org/t/using-option-outside-tasks/12290/1 "2015-10-19T15:31:32Z")

</div>

Hi to all,

we use in many scenarois the @Option annotation to delegate some parameters to our tasks. At one implementation I have a little problem:

We have the necessity to do some actions before running the integrationtests (e.g. creating database structure, import testdata etc.) This we have implemented by configuring a test task for our needs and add some pre and post actions.  
(doFirst and doLast). This things are recommended when running the tests the first time. All the other test runs they are obsolete. So we want to invent a commandline option like “–skipPre” or “–skipPost” to skip these things. How can I access the information if this command line parameter is used?

Any help would be welcome  
Cheers  
Markus

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [October 19, 2015, 3:58pm UTC](https://discuss.gradle.org/t/using-option-outside-tasks/12290/2 "2015-10-19T15:58:29Z")

</div>

Just turn your doFirst/doLast actions into separate tasks and use task dependencies.

e.g.,

```gradle
task preTask
task postTask
task test 
test.dependsOn preTask
test.finalizedBy postTask

```

Then you can either make preTask incremental (so it knows not to run), use `onlyIf` to force the preTask to run, or you can skip the preTask with -x (`gradle test -x preTask`).

If the tasks don’t _have_ to run before the test (the test would work without ever running preTask), you could also just use `test.mustRunAfter preTask` and then it would only run if someone explicitly asks for it (`gradle test preTask`).
