Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable ordering of urls in gradle resolve task #3877

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.v3.plugins.gradle.tasks;

import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
Expand Down Expand Up @@ -315,30 +316,30 @@ public void resolve() throws GradleException {
}
LOGGER.info( "Resolving OpenAPI specification.." );

Set<URL> urls = StreamSupport.stream(getClasspath().spliterator(), false).map(f -> {
Stream<URL> classpathStream = StreamSupport.stream(getClasspath().spliterator(), false).map(f -> {
try {
return f.toURI().toURL();
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
throw new GradleException(
String.format("Could not create classpath for annotations task %s.", getName()), e);
String.format("Could not create classpath for annotations task %s.", getName()), e);
}
}).collect(Collectors.toSet());
});

Set<URL> buildUrls = StreamSupport.stream(getBuildClasspath().spliterator(), false).map(f -> {
Stream<URL> buildClasspathStream = StreamSupport.stream(getBuildClasspath().spliterator(), false).map(f -> {
try {
return f.toURI().toURL();
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
throw new GradleException(
String.format("Could not create classpath for annotations task %s.", getName()), e);
String.format("Could not create classpath for annotations task %s.", getName()), e);
}
}).collect(Collectors.toSet());
});

urls.addAll(buildUrls);
URL[] urls = Stream.concat(classpathStream, buildClasspathStream)
.distinct()
.toArray(URL[]::new);

//ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
ClassLoader classLoader = new URLClassLoader(urls);

try {
Class swaggerLoaderClass = classLoader.loadClass("io.swagger.v3.jaxrs2.integration.SwaggerLoader");
Expand Down