# Multi-module tests running problem

**URL:** <https://discuss.gradle.org/t/multi-module-tests-running-problem/48594>\
**Category:** Help/Discuss\
**Created:** [May 31, 2024, 11:48am UTC](https://discuss.gradle.org/t/multi-module-tests-running-problem/48594 "2024-05-31T11:48:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ekadov](https://avatars.discourse-cdn.com/v4/letter/e/dec6dc/32.png) [@ekadov](https://discuss.gradle.org/u/ekadov)\
**Post date:** [May 31, 2024, 11:48am UTC](https://discuss.gradle.org/t/multi-module-tests-running-problem/48594/1 "2024-05-31T11:48:10Z")

</div>

Hi.  
Need your help.  
There is a multi-module project with the following Gradle-structure:

├── build.gradle  
├── settings.gradle  
├── /sub1  
│ └── build.gradle  
├── /sub2  
│ └── build.gradle

The main goal is to run tests from a commandline by passing some variables inside. I want to run tests from each module and specific task separately. For example, to run tests from ‘sub1’ and with ‘task1’. Or from ‘sub1’ and with ‘task2’ and etc. Tasks should contain some specific logic to run with.  
The problem is that I can not solve a problem of using task and module. Because, as I think, task should be in a root build.gradle. So, what logic should be stored in a module gradle config or it should be empty at all?  
Can anyone help to solve it?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [May 31, 2024, 12:01pm UTC](https://discuss.gradle.org/t/multi-module-tests-running-problem/48594/2 "2024-05-31T12:01:42Z")

</div>

It’s a bit unclear to me what you mean.

To run `task1` from `sub1` you would just run `./gradlew :sub1:task1`, same for `./gradlew :sub1:task2`.

> Because, as I think, task should be in a root build.gradle.

Task should only bei in root `build.gradle` if it is for the root project.  
You should not add tasks to subprojects from root build script.  
That is called cross-project configuration and is highly discouraged bad practice  
which introduces project coupling and and disturbs or disables more sophisticated Gradle features or optimizations.

So no, the subprojects build scripts should never be empty.

If you want to share common build logic, you should use [convention plugins](https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html#sec:convention_plugins) in `buildSrc` or an [included build](https://docs.gradle.org/current/userguide/composite_builds.html), for example implemented as [precompiled script plugin](https://docs.gradle.org/current/userguide/custom_plugins.html#sec:precompile_script_plugin).

Then you apply this convention plugin where you want its effect to be in place.
