Search code examples
javatestingjunit5annotation-processinggoogle-compile-testing

How to provide some library from maven to Google Compile-Testing


I'm writing a tests for my annotation processor with Google Compile-Testing and JUnit.

How to provide some libraries, which present at maven(as example, "somegroup:somelib:1.0"), to compilation?

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

Solution

  • It can be reached by using withClasspathFrom for provide to test compilation all classes which available at test itself:

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