Repository: quarkusio/quarkus
Issue: Quarkus 1.3.0.Final gradle does not start with Undertow Servlet

**Describe the bug**
When I include Undertow Servlet in a Gradle project, quarkus application does not start.

**Expected behavior**
Quarkus app should start without throwing an error

**Actual behavior**
(Describe the actual behavior clearly and concisely.)


**To Reproduce**
Steps to reproduce the behavior:
1.  Go to https://code.quarkus.io/ 
2.  Change Build Tool to: Gradle
3.  Add Undertow Servlet as a dependency.
4. Generate project
5. Try running with quarkusDev build task.

Project throws java.lang.ExceptionInInitializerError

The same configuration when used with maven starts fine.


**Environment (please complete the following information):**
 - Output of `uname -a` or `ver`: 
 - Output of `java -version`: 
 - GraalVM version (if different from Java): 
 - Quarkus version or git rev: 
 - Build tool (ie. output of `mvnw --version` or `gradlew --version`): 

**Additional context**
(Add any other context about the problem here.)


Changed files:
independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java

diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java
index ddfaf1b3481..8f489ad1672 100644
--- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java
+++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java
@@ -34,6 +34,7 @@
 public class QuarkusClassLoader extends ClassLoader implements Closeable {
 
     private static final Logger log = Logger.getLogger(QuarkusClassLoader.class);
+    protected static final String META_INF_SERVICES = "META-INF/services/";
 
     static {
         registerAsParallelCapable();
@@ -132,6 +133,27 @@ public Enumeration<URL> getResources(String nm) throws IOException {
         //        resources.add(element.getResource(nm).getUrl());
         //    }
         //}
+
+        //this is a big of a hack, but is nessesary to prevent service leakage
+        //in some situations (looking at you gradle) the parent can contain the same
+        //classes as the application. The parent aggregation stops this being a problem
+        //in most cases, however if there are no actual implementations of the service
+        //in the application then this can still cause problems
+        //this approach makes sure that we don't load services that would result
+        //in a ServiceConfigurationError
+        //see https://github.com/quarkusio/quarkus/issues/7996
+        if (name.startsWith(META_INF_SERVICES)) {
+            try {
+                Class<?> c = loadClass(name.substring(META_INF_SERVICES.length()));
+                if (c.getClassLoader() == this) {
+                    //if the service class is defined by this class loader then any resources that could be loaded
+                    //by the parent would have a different copy of the service class
+                    banned = true;
+                }
+            } catch (ClassNotFoundException ignored) {
+                //ignore
+            }
+        }
         for (ClassPathElement i : elements) {
             ClassPathResource res = i.getResource(nm);
             if (res != null) {