Gradleの中にプラグインを作成しようとすると、私は何を理解することはできません私は、プラグインを実装する必要があります

jhell:

だから、これは私の現在のあるbuild.gradleファイル:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.6.1/userguide/java_library_plugin.html
 */

apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'

repositories {
    google()
}

dependencies {
     compile gradleApi()
}

私はGradleのドキュメントで読んだすべてのものから、私はこれは私が実際にプラグインを作成する必要があるのすべてであると信じています。私はorg.gradleパッケージからプラグインをインポートすることができることを意味していることによります。

しかし、org.gradleは私のビルド・パス上で見つけることができません。

他に何をする必要がありますか?

フランシスコ・マテオ:

あなたは、私はあなたがあなたのローカルマシン上のGradleをインストールしていると仮定していて、あなたが使用Gradleのビルドでコメントから判断するとgradle init、あなたが今持っているものを生成します。あなたが発生した場合を除きjava-library、ビルドの種類を、あなたはGradleのプラグインのビルドタイプを生成している必要があるとき。

あなたが持っているので、groovyプラグインが適用され、私はあなたがそう簡単に実行し、GroovyのベースのGradleプラグインをしたいと仮定しgradle init、再び、しかし、選択groovy-gradle-pluginのタイプをプラグイン例えば、私のローカルマシン上のGradle 6.2.2を使用して、Groovyのショーを使用してのGradleプラグインプロジェクトを生成するための私の端子出力:

➜  gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 4

Select implementation language:
  1: Groovy
  2: Java
  3: Kotlin
Enter selection (default: Java) [1..3] 1

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Project name (default: example-groovy): 

Source package (default: example.groovy): 


> Task :init
Get more help with your project: https://guides.gradle.org?q=Plugin%20Development

BUILD SUCCESSFUL in 17s
2 actionable tasks: 2 executed

だから今私は、次のディレクトリ構造とファイルを持っています:

├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
    ├── functionalTest
    │   └── groovy
    │       └── example
    │           └── groovy
    │               └── ExampleGroovyPluginFunctionalTest.groovy
    ├── main
    │   ├── groovy
    │   │   └── example
    │   │       └── groovy
    │   │           └── ExampleGroovyPlugin.groovy
    │   └── resources
    └── test
        ├── groovy
        │   └── example
        │       └── groovy
        │           └── ExampleGroovyPluginTest.groovy
        └── resources

そして、生成されたGradleのビルドファイルの内容:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Gradle plugin project to get you started.
 * For more details take a look at the Writing Custom Plugins chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.2.2/userguide/custom_plugins.html
 */

plugins {
    // Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
    id 'java-gradle-plugin'

    // Apply the Groovy plugin to add support for Groovy
    id 'groovy'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // Use the awesome Spock testing and specification framework
    testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
}

gradlePlugin {
    // Define the plugin
    plugins {
        greeting {
            id = 'example.groovy.greeting'
            implementationClass = 'example.groovy.ExampleGroovyPlugin'
        }
    }
}

// Add a source set for the functional test suite
sourceSets {
    functionalTest {
    }
}

gradlePlugin.testSourceSets(sourceSets.functionalTest)
configurations.functionalTestImplementation.extendsFrom(configurations.testImplementation)

// Add a task to run the functional tests
task functionalTest(type: Test) {
    testClassesDirs = sourceSets.functionalTest.output.classesDirs
    classpath = sourceSets.functionalTest.runtimeClasspath
}

check {
    // Run the functional tests as part of `check`
    dependsOn(tasks.functionalTest)
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=345294&siteId=1