首页 > 解决方案 > 如何提供一些从 maven 到 Google Compile-Testing 的库

问题描述

我正在使用 Google Compile-Testing 和 JUnit 为我的注释处理器编写测试。

如何提供一些存在于 maven 的库(例如,"somegroup:somelib:1.0")来编译?

Compilation compilation = Compiler.javac().withProcessors(new MyProcessor())
                .withClasspath(???) //What's there to use?
                .compile(
                        JavaFileObjects.forResource("path/to/SomeClass.java")
                        ...
                );

标签: javatestingjunit5annotation-processinggoogle-compile-testing

解决方案


它可以通过使用withClasspathFromfor provide 来测试编译测试本身可用的所有类来实现:

Compilation compilation = Compiler.javac().withProcessors(new MyProcessor())
                .withClasspathFrom(this.getClass().getClassLoader())
                .compile(
                        JavaFileObjects.forResource("path/to/SomeClass.java")


推荐阅读