有如下 Maven 插件代码: @Mojo(name = "generate") public class GenerateMojo extends AbstractMojo { @Parameter(defaultValue = "${project.build.outputDirectory}", required = true) private File outputDirectory; @Parameter private File outputFile; @Override public void execute() throws MojoExecutionException, MojoFailureException { Set permissionCodeSet = new HashSet(); URL url; try { url = outputDirectory.toURI().toURL(); } catch (MalformedURLException e) { throw new RuntimeException(e); } getLog().info(url.toString()); Reflections reflections = new Reflections( new ConfigurationBuilder() .addUrls(url) .setScanners(MethodsAnnotated)); reflections.getStore().forEach((s, stringSetMap) -> { stringSetMap.forEach((k, v) -> { System.out.println(k); v.forEach(System.out::println); System.out.println(); }); }); Set resources = reflections.get(MethodsAnnotated.with(GetMapping.class).as(Method.class)); System.out.println("resources = " + resources); Set methodSet = reflections.get(MethodsAnnotated.with(SaCheckPermission.class).as(Method.class)); getLog().info(methodSet.toString()); methodSet.forEach(method -> { SaCheckPermission saCheckPermission = method.getAnnotation(SaCheckPermission.class); List values = List.of(saCheckPermission.value()); permissionCodeSet.addAll(values); }); getLog().info(permissionCodeSet.toString()); } } Reflections 能够正确实例化并扫描成功,日志如下: [INFO] Reflections took 67 ms to scan 1 urls, producing 7 keys and 79 values 尝试打印 store 内容也正确,但 methodSet 和 permissionCodeSet 均为空 尝试在使用插件的项目中运行上述代码,能够正常输出内容。