我错过了什么方法?我得到一个 MissingMethodException
project.apply plugin: 'env'
这是我的代码:
--EnvPluginTest.groovy
package com.gradle.env;
import static org.junit.Assert.*
import org.junit.Test
import org.gradle.api.*
import org.gradle.testfixtures.*
class EnvPluginTest {
@Test
public void EnvPluginAddsEnvPluginExtensionToProject() {
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'env'
assertTrue(project.extensions.getByName('env')
instanceof EnvPluginExtension)
}
}
--env.properties
implementation-class=com.gradle.env.EnvPlugin
--EnvPlugin.groovy
package com.gradle.env
import org.gradle.api.*;
class EnvPlugin implements Plugin<Project> {
void apply(Project project) {
project.configure {
extensions.create("env",
EnvPluginExtension)
}
}
}
class EnvPluginExtension {
def env = EnvSingleton.instance
}
class EnvSingleton {
String tcserverHome
String javaHome
private static final INSTANCE = new EnvSingleton()
private EnvSingleton() {}
static getInstance() {
return INSTANCE
}
}