我想把一些常用的配置(比如java、intellij、gradle、kotlin的东西)放到一个外部文件中,并分享给其他项目。
// myPropject/build.gradle.kts
buildscript {
apply("/home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts")
}
这是一个外部文件:
///home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts
repositories {
mavenLocal()
jcenter()
mavenCentral()
gradlePluginPortal()
maven {
url=uri("https://plugins.gradle.org/m2/")
}
}
apply(plugin = "java")
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
以下是错误信息:
> Configure project :
e: /home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts:15:1: Expression 'java' cannot be invoked as a function. The function 'invoke()' is not found
e: /home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts:15:1: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val PluginDependenciesSpec.java: PluginDependencySpec defined in org.gradle.kotlin.dsl
e: /home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts:16:5: Unresolved reference: toolchain
e: /home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts:17:9: Unresolved reference: languageVersion
FAILURE: Build failed with an exception.
* Where:
Script '/home/xiaojie/IdeaProjects/Config/gradle/kotlin/java-11/env.gradle.kts' line: 15
* What went wrong:
Script compilation errors:
Line 15: java {
^ Expression 'java' cannot be invoked as a function. The function 'invoke()' is not found
Line 15: java {
^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val PluginDependenciesSpec.java: PluginDependencySpec defined in org.gradle.kotlin.dsl
Line 16: toolchain {
^ Unresolved reference: toolchain
Line 17: languageVersion.set(JavaLanguageVersion.of(11))
^ Unresolved reference: languageVersion