Gradle 插件示例
版本 8.7
您可以使用 IntelliJ 原生导入器 或 Eclipse Buildship 在 IDE 中打开此示例。 |
此示例展示了如何在 Java 语言中构建 Gradle 插件。
greeting-plugin/build.gradle.kts
plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
`java-gradle-plugin`
}
repositories {
// Use Maven Central for resolving dependencies
mavenCentral()
}
dependencies {
// Use JUnit test framework for unit tests
testImplementation("junit:junit:4.13")
}
gradlePlugin {
// Define the plugin
val greeting by plugins.creating {
id = "com.example.plugin.greeting"
implementationClass = "com.example.plugin.GreetingPlugin"
}
}
greeting-plugin/build.gradle
plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
id 'java-gradle-plugin'
}
repositories {
// Use Maven Central for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
}
dependencies {
// Use JUnit test framework for unit tests
testImplementation 'junit:junit:4.13'
}
gradlePlugin {
// Define the plugin
plugins {
greeting {
id = 'com.example.plugin.greeting'
implementationClass = 'com.example.plugin.GreetingPlugin'
}
}
}
有关插件开发的更详细指南,请参阅 插件开发指南。
您也可以使用 gradle init
在本地生成此项目。