Skip to content
Advertisement

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")
                        ...
                );

Advertisement

Answer

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")


User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement