# Gradle - run tests and exports by pattern filter

**URL:** <https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116>\
**Category:** GENERAL\
**Created:** [March 24, 2021, 12:39pm UTC](https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116 "2021-03-24T12:39:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stbischof](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/stbischof/32/59_2.png) [@stbischof](https://bnd.discourse.group/u/stbischof)\
**Post date:** [March 24, 2021, 12:39pm UTC](https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116/1 "2021-03-24T12:39:08Z")

</div>

At the moment the testOSGi task runs all bnd.bnd files as test and testrun.xxx let me run a single test.  
It would be great to have more control.

Is there any Option to run all osgitest/exports/resolve in gradle using an filter patter as it is possible in maven and bnd-cli?

./gradlew testrun.[myTestGlob.bndrun]  
./gradlew export.[myExportGlob.bndrun]  
./gradlew resolve.[myResolveGlob.bndrun]

regards

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [March 24, 2021, 1:02pm UTC](https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116/2 "2021-03-24T13:02:27Z")

</div>

I don’t think I understand your question. Just ask gradle to run the tasks you want to run. If you want to create a gradle task which depends on some subset of the predefined tasks, do it!

---

<div class="post-metadata">

**Author:** ![stbischof](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/stbischof/32/59_2.png) [@stbischof](https://bnd.discourse.group/u/stbischof)\
**Post date:** [March 24, 2021, 1:35pm UTC](https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116/3 "2021-03-24T13:35:45Z")

</div>

Let me try to explaine it a bit more clearly

As far as is know, in gradle, it is only possible to run a runtest task by its concrete name.  
If I have \>10 ‘test-xyz.bndrun’ files in my workspace i do not want to run it one by one by its name.  
like:

```auto
./gradlew testrun.testrun-1
....
./gradlew testrun.testrun-10

```

more handsome would be:  
./gradlew testrun.test\*.bndrun

An other issue is that if you have in each project of your workspace and ‘test.bndrun’ file. I can’t see a way to run an explicit test.bndrun of an specific project.

maybe all this is possible. but it did not find a way how to easiely run it.

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [March 24, 2021, 1:53pm UTC](https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116/4 "2021-03-24T13:53:18Z")

</div>

> [@stbischof](#):
>
> ./gradlew testrun.test\*.bndrun

You want a new gradle feature. You should ask gradle about that. Bnd cannot “fix” that.

> [@stbischof](#):
>
> An other issue is that if you have in each project of your workspace and ‘test.bndrun’ file. I can’t see a way to run an explicit test.bndrun of an specific project.

You can use the full path of the task. For the `p1` project, do `./gradlew :p1:testrun.test`. This will run the `testrun.test` task in the `p1` project.

---

<div class="post-metadata">

**Author:** ![ejjcase](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/ejjcase/32/312_2.png) [@ejjcase](https://bnd.discourse.group/u/ejjcase)\
**Post date:** [October 8, 2025, 9:52am UTC](https://bnd.discourse.group/t/gradle-run-tests-and-exports-by-pattern-filter/116/5 "2025-10-08T09:52:56Z")

</div>

I’m coming to this late, but you can do it in Gradle by defining a task that depends on all the test tasks. For example (in Kotlin):

```auto
tasks.register("allOSGiTests") {
  dependsOn(tasks.withType(TestOSGi::class))
}

```

Since a `TestOSGi` task is generated automatically for each `bndrun` file, running `allOSGiTests` should then run all the tests.
