FileSystemProvider registration fails in custom plugin


in a custom Gradle plugin, we are using a “sftp-fs” library in a custom Task which provides support for sftp nio.2 file systems. If the library is on the classpath, it will register a FileSystemProvider. I still keep getting a ProviderNotFoundException “Provider ‘sftp’ not found”.

Printing the buildscript classpath, shows the lib

task showClasspath() {
    doLast() {
        buildscript.configurations.classpath.each { println it }

But when I print the classpath from the plugin/task code with System.out.println(System.getProperties().get("java.class.path")); it only shows


a) Does it not work since the classpath for the custom task is only the gradle-launcher?
b) If so, is there some proper solution for this problem (SPI)?


Assuming you are using FileSystems.newFileSystem, have you tried using one of the overloads that takes a ClassLoader, passing it the classloader of your plugin/task class? The classloader of your plugin/task class should have the sftp-fs library.

Thanks @Chris_Dore. Works like a charm.