【问题标题】:How to provide some library from maven to Google Compile-Testing如何提供一些从 maven 到 Google Compile-Testing 的库
【发布时间】:2021-02-13 12:24:59
【问题描述】:

我正在使用 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")
                        ...
                );

【问题讨论】:

  • 我通过提供像 .withClasspath(ImmutableList.of( new File("C:\\Users\\hohserg\\.gradle\\caches\\modules-2\\files-2.1\\io.netty\\netty-all\\4.1.25.Final\\d0626cd3108294d1d58c05859add27b4ef21f83b\\netty-all-4.1.25.Final.jar"))) 这样的下载库来解决它,但它看起来很诡异

标签: java testing junit5 annotation-processing google-compile-testing


【解决方案1】:

可以通过使用withClasspathFrom 来提供测试编译所有测试本身可用的类:

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

【讨论】:

    猜你喜欢
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 2014-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    相关资源
    最近更新 更多