Skip to content
Open
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,8 +1,12 @@
package ch.ivyteam.ivy.maven.compile;

import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -97,7 +101,11 @@ private ContextBuilder(MavenProject project, MavenSession session) {
}

private ProjectValidatorContext build() {
return ProjectValidatorContext.create().project(toProject()).allProjects(toAllProjects()).toContext();
return ProjectValidatorContext.create()
.project(toProject())
.allProjects(toAllProjects())
.classLoader(toClassLoader())
.toContext();
}

private Project toProject() {
Expand Down Expand Up @@ -141,5 +149,23 @@ private List<Project> toAllProjects() {
.map(BasicProjectBuilder::build)
.toList();
}

private ClassLoader toClassLoader() {
try {
var classpath = project.getCompileClasspathElements();
var urls = classpath.stream()
.map(path -> {
try {
return Path.of(path).toUri().toURL();
} catch (Exception e) {
throw new RuntimeException(e);
}
})
.toArray(URL[]::new);
return new URLClassLoader(urls, null);
} catch (DependencyResolutionRequiredException ex) {
throw new RuntimeException(ex);
}
}
}
}
Loading