我试图编写一个类似于众所周知的exec:java
mojo的Maven插件。它创建了一个类加载器,将项目的工件加载到Maven的JVM中,并对它们做了一些事情。这是我创建类加载器的代码:
Set<URL> urls = new HashSet<URL>();
try {
for (Object artifactObject : project.getCompileArtifacts()) {
Artifact artifact = (Artifact) artifactObject;
urls.add(artifact.getFile().toURI().toURL());
}
urls.add(project.getArtifact().getFile().toURI().toURL());
} catch (MalformedURLException ex) {
throw new RuntimeException(ex); // this really shouldn't happen
}
ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
根据我找不到的文档,exec:java
的源代码,project.getCompileArtifacts()
应该返回与编译范围的直接和间接依赖关系。但它正在返回一个空列表。什么了?