Without loss of generality, suppose you have an open source Java project with Gradle as the build system, and you want to add the MIT licence to it. Consider the cases:
Case 1. From the build.gradle file you decleare a depedency on JUnit5 which is licenced under Eclipse Public License - v 2.0. You make a few tests with it in a test folder, and all that along with a src folder is uploaded on GitHub. Can your project be licenced under MIT? Furthermore, you will create a package with your project, but the JUnit5 tests will not be included in it.
Case 2. From the build.gradle file you decleare a depedency on java-annotations from JetBrains, which is licenced under Apache License 2.0. Can your project be licenced under MIT? Furthermore, you will create a package with your project, and you want the dependeds to view the annotations on your code, but you are not concerned if they can use the annotations in their code.
TL;DR: I understand that if you copy and paste the files of a project you can only re-licence it with compatible licenses, but does the same hold true if you only depend on them via Maven/Gradle packages and your produced project package will not contain them?