Kotlin Gradle plugin not resolving classpath from local directory

I’m trying to use the Kotlin Gradle plugin by loading the plugin artifacts and all its runtime dependencies from a local directory. However, the plugin is not able to find the kotlin-scripting-compiler-embeddable dependency, even though this JAR (and all its transitive runtime dependencies) is in the classpath.

My directory structure is:

$ ls
build.gradle  libs  settings.gradle  src
$ ls libs
kotlin-android-extensions-1.3.20.jar            kotlin-gradle-plugin-1.3.20.jar                  kotlin-script-runtime-1.3.20.jar  
kotlin-annotation-processing-gradle-1.3.20.jar  kotlin-gradle-plugin-api-1.3.20.jar              kotlin-stdlib-1.3.20.jar          
kotlin-compiler-embeddable-1.3.20.jar           kotlin-gradle-plugin-model-1.3.20.jar            trove4j-1.0.20181211.jar          
kotlin-compiler-runner-1.3.20.jar               kotlin-reflect-1.3.20.jar                                                          
kotlin-daemon-client-1.3.20.jar                 kotlin-scripting-compiler-embeddable-1.3.20.jar                                    ```

My build.gradle is:

buildscript {                                                                 
    dependencies {                                                            
        classpath fileTree(dir: 'libs', include: '*.jar')                     
    }                                                                         
}                                                                             

apply plugin: 'kotlin'                                                        
                                                                              
dependencies {                                                                
    kotlinCompilerClasspath fileTree(dir: 'libs', include: '*.jar')           
    kotlinCompilerPluginClasspath fileTree(dir: 'libs', include: '*.jar')     
}                                                                             

And the problem is:

$ gradle assemble                                                                                                                            
Picked up _JAVA_OPTIONS: -Xmx900m                                                                                                            
> Task :compileKotlin FAILED                                                                                                                 
                                                                                                                                             
FAILURE: Build failed with an exception.                                                                                                     
                                                                                                                                             
* What went wrong:                                                                                                                           
Execution failed for task ':compileKotlin'.                                                                                                  
> Could not resolve all files for configuration ':kotlinCompilerPluginClasspath'.                                                            
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.20 because no repositories are defined.
     Required by:                                                                                                                            
         project :                                                                                                                           
...                                                                                                                                             

To reproduce the failure, there must be at least one Kotlin file in src/main/kotlin (even if it’s empty).

I’m using Gradle 4.10.2.

Please note: I’m aware that adding an external repository to the project (like mavenCentral) solves the problem, as explained e.g. here. However, I have the requirement to resolve all build artifacts locally (including gradle plugins), without connecting to any repository.

Am I doing something wrong? Is there a limitation in how the plugin resolves the classpath that doesn’t allow this (admittedly uncommon) use case?

Thanks in advance.

I also tried adding the transitive compile (not just runtime) dependencies to the classpath, just in case:

$ ls libs                                                                                                                                   
annotations-17.0.0.jar                          kotlin-daemon-client-1.3.20.jar        kotlin-scripting-compiler-embeddable-1.3.20.jar      
kotlin-android-extensions-1.3.20.jar            kotlin-gradle-plugin-1.3.20.jar        kotlin-script-runtime-1.3.20.jar                     
kotlin-annotation-processing-gradle-1.3.20.jar  kotlin-gradle-plugin-api-1.3.20.jar    kotlin-stdlib-1.3.20.jar                             
kotlin-build-common-1.3.20.jar                  kotlin-gradle-plugin-model-1.3.20.jar  kotlin-stdlib-common-1.3.20.jar                      
kotlin-compiler-embeddable-1.3.20.jar           kotlin-native-utils-1.3.20.jar         trove4j-1.0.20181211.jar                             
kotlin-compiler-runner-1.3.20.jar               kotlin-reflect-1.3.20.jar                                                                   

Same result though.

I finally solved the problem with the set of dependencies indicated in the original post, and the following build.gradle:

buildscript {
    dependencies {
        classpath fileTree(dir: 'libs', include: '*.jar')
    }
}

apply plugin: 'kotlin'

repositories {
    flatDir(dir: 'libs')
}

dependencies {
    kotlinCompilerClasspath fileTree(dir: 'libs', include: '*.jar')
}

Strangely, it is necessary to indicate both the explicit classpath and the flatDir repo… Probably something could be improved in the Kotlin Gradle plugin to simplify this.

I’m having the same error, however I’m using kotlin dsl instead of groovy gradle
I modified the project gradle file to this:

but getting an error: e: /…/build.gradle.kts:30:9: Unresolved reference: kotlinCompilerClasspath

	import de.fayard.OrderBy
	import de.fayard.internal.PluginConfig.isNonStable
	import org.jetbrains.kotlin.config.KotlinCompilerVersion


	plugins {
	    id("de.fayard.refreshVersions") version Versions.de_fayard_refreshversions_gradle_plugin
	    kotlin("multiplatform") version "1.3.50"
	    kotlin("plugin.serialization") version Versions.kotlin_serialization
	}


	buildscript {
	    repositories {
	        google()
	        jcenter()
	    }

	    dependencies {
	        classpath(Libs.kotlin_serialization)
	        classpath(Libs.kotlin_gradle_plugin)
	        classpath(Libs.com_android_tools_build_gradle)
	        kotlinCompilerClasspath(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
	        // kotlinCompilerPluginClasspath(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
	    }

	    repositories {
	        google()
	        jcenter()
	        mavenCentral()
	    }
	}