gpt4 book ai didi

java - ReflectionsException : Could not get type for name org. gradle.api.Plugin

转载 作者:搜寻专家 更新时间:2023-11-01 03:31:08 24 4
gpt4 key购买 nike

我已经实现了自定义 Gradle 插件并且它可以工作,但是在 Gradle 构建期间我有一个 ReflectionsException: Could not get the type for name org.gradle.api.Plugin因为反射扫描。为什么类加载器看不到类型?

Caused by: java.lang.ClassNotFoundException: org.gradle.api.Plugin
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:388)

自定义插件实现Plugin<Project>如下所示:

//CommonGradlePlugin
import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class CommonGradlePlugin implements Plugin<Project> {
//...
}

最佳答案

Why class loader doesn't see the type?

我想 gradle 类不包含在编译/运行时类路径中,只是因为它是一个构建工具。这就是 Reflections 无法找到 gradle 类的原因。

您可以使用 Reflection 的 ConfigurationBuilder 排除带有 gradle 插件的包:

ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
FilterBuilder filterBuilder = new FilterBuilder();

configurationBuilder.addUrls(ClasspathHelper.forPackage(PACKAGE_TO_SCAN));
filterBuilder
.includePackage(PACKAGE_TO_SCAN)
.excludePackage(PACKAGE_TO_EXCLUDE);
configurationBuilder.filterInputsBy(filterBuilder);

Reflections reflections = new Reflections(configurationBuilder);

关于java - ReflectionsException : Could not get type for name org. gradle.api.Plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54405553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com