【发布时间】:2019-11-28 09:19:23
【问题描述】:
我需要将一个文件从 gradle 插件 jar 复制到项目的根目录,该项目将插件作为 gradle 任务的一部分应用。
我在 gradle 插件 jar 中有一个文件放在 src/main/resources/data/file
我在 gradle 任务中有以下代码:
String filename = "data" + File.separator + "file";
final InputStream stream= classLoader.getResourceAsStream(fileName);
final Path filePath = new File(filename).toPath();
new File("data").mkdirs();
try {
Files.copy(stream, filePath , StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new PluginApplicationException("Failed to apply plugin", e);
}
我希望这段代码从 gradle 插件 jar 中获取一个文件并将其放入 /data/file。
当我运行插件任务时,它在 linux 上运行良好,但它在 windows 上崩溃,因为classLoader.getResourceAsStream(fileName); 返回 null。
我尝试使用不同的方式来获取类加载器,但它在 windows 和 linux 上始终是 VisitableURLClassLoader。有人知道为什么它在 Windows 上为空吗?
【问题讨论】:
标签: java gradle gradle-plugin