# Would running a unit test in Eclipse respect classpath exclusions?

**URL:** https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977
**Category:** Buildship
**Created:** [June 15, 2017, 7:27pm UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977 "2017-06-15T19:27:10Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Karr](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_karr/32/145_2.png) [@David\_Karr](https://discuss.gradle.org/u/David_Karr)
#### Post date: [June 15, 2017, 7:27pm UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/1 "2017-06-15T19:27:10Z")

</div>

I’m asking about something that I haven’t tried. I noticed a small limitation of Maven-based projects in Eclipse, and I was wondering if Gradle projects with Buildship would have the same issue. I won’t feel any less for Buildship if it does 🙂 , but it would be good to know if this works better in Gradle/Buildship.

If I have a Maven project with both unit tests and PaxExam integration tests, when I run a unit test it will have the PaxExam dependencies in the classpath. For me, this doesn’t cause things to break, but there’s a minor annoyance with configuring debug levels, in that it ends up consulting a pax artifact to determine whether debug logging is enabled, even though I’m not using pax in the test.

I can configure Maven Surefire to exclude those dependencies, so that when the Maven build runs, it doesn’t get confused about logging levels, but Eclipse m2e doesn’t have this level of integration, so running the unit test in eclipse still has pax artifacts in the classpath, resulting in annoying logging.

In a Buildship project, would “Run As Unit Test” in Eclipse have more intelligence, assuming my build.gradle had logic to ensure that unit tests only have unit test dependencies?

---

<div class="post-metadata">

### Author: ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)
#### Post date: [June 16, 2017, 8:20am UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/2 "2017-06-16T08:20:53Z")

</div>

No, Buildship doesn’t separate dependency scopes at runtime. In fact, the classpath for each Buildship project is a union of all dependency scopes. We know this is suboptimal, but we will do some investigation how to improve this in the near future, so stay tuned.

---

<div class="post-metadata">

### Author: ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)
#### Post date: [June 16, 2017, 2:28pm UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/3 "2017-06-16T14:28:29Z")

</div>

@David_Karr There’s a `Run as Gradle Test` feature in Buildship that might be useful to this story. Just select a class or method in Eclipse (in the source editor, in the package explorer, or in the outline view), and from the context menu choose `Run As.. > Run as Gradle Test`. This will invoke Gradle directly to execute your test and therefore will have the correct classpath.

You can also re-execute tests. To do that, just find the node representing your test class/method in the Executions view, and from its context menu execute the relaunch.

---

<div class="post-metadata">

### Author: ![Max\_Bruchmann](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/max_bruchmann/32/620_2.png) [@Max\_Bruchmann](https://discuss.gradle.org/u/Max_Bruchmann)
#### Post date: [June 29, 2017, 10:10am UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/4 "2017-06-29T10:10:00Z")

</div>

@donat We are facing a similar problem as our multi project spring based project is heavily based on classpath scanning and mixing beans from other projects’ test sources makes a lot of unwanted side effects.

It kind of works with the “Run as \> Gradle Test” approach.  
Unfortunately it looks like runs always everything and it feels like there is a lot happening in the UI thread so the whole eclipse ui gets a bit unresponsive. Also it would be great to make this as “Debug as” option available

---

<div class="post-metadata">

### Author: ![donat](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/donat/32/7798_2.png) [@donat](https://discuss.gradle.org/u/donat)
#### Post date: [June 30, 2017, 9:30am UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/5 "2017-06-30T09:30:15Z")

</div>

@Max_Bruchmann The UI responsiveness is [fixed](https://github.com/eclipse/buildship/issues/439) in the upcoming [2.1.0](https://projects.eclipse.org/projects/tools.buildship/releases/2.1.0) release. If you have some time, please [install the latest snapshot](https://github.com/eclipse/buildship/blob/master/docs/user/Installation.md) and give it a try, we’d appreciate the feedback.

The debugging feature is one of the many things we want to add to Buildship. Please give your 👍 to the related [issue](https://github.com/eclipse/buildship/issues/249) so that we can prioritize the implementation.

---

<div class="post-metadata">

### Author: ![Max\_Bruchmann](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/max_bruchmann/32/620_2.png) [@Max\_Bruchmann](https://discuss.gradle.org/u/Max_Bruchmann)
#### Post date: [June 30, 2017, 10:02am UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/6 "2017-06-30T10:02:20Z")

</div>

Hi,  
just tried the:  
`Buildship: Eclipse Plug-ins for Gradle	2.1.0.v20170629-2316-s	org.eclipse.buildship.feature.group	Eclipse Buildship`

But it looks like the UI issue is still there using Neon.2 Release (4.6.2)

As for my problem with the united classpath I moved all test sources into separate projects which works but of course is not the ideal solution

---

<div class="post-metadata">

### Author: ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)
#### Post date: [June 30, 2017, 11:15am UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/8 "2017-06-30T11:15:07Z")

</div>

> [@Max\_Bruchmann](#):
>
> But it looks like the UI issue is still there using Neon.2 Release (4.6.2)

Can you give us some more info on what UI issue exactly you are seeing? Maybe a little screencast?

---

<div class="post-metadata">

### Author: ![Max\_Bruchmann](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/max_bruchmann/32/620_2.png) [@Max\_Bruchmann](https://discuss.gradle.org/u/Max_Bruchmann)
#### Post date: [July 3, 2017, 2:02pm UTC](https://discuss.gradle.org/t/would-running-a-unit-test-in-eclipse-respect-classpath-exclusions/22977/9 "2017-07-03T14:02:24Z")

</div>

Hi @st_oehme for some reason I cannot reproduce it anymore, maybe there was something stuck on eclipse side. Sorry for the false alarm

I let you know if it happens again
