Unverified Commit aa88309f authored by daz's avatar daz
Browse files

Update gradle-plugin sample to use Kotlin DSL

parent 086c9e4b
Loading
Loading
Loading
Loading
+2
Changes for .github/workflow-samples/gradle-plugin/gradle/libs.versions.toml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
−60

File deleted.

+40
Changes for .github/workflow-samples/gradle-plugin/plugin/build.gradle.kts: 40 added lines, 0 removed lines.
Original line number Diff line number Diff line
plugins {
    `java-gradle-plugin`
}

repositories {
    mavenCentral()
}

testing {
    suites {
        val test by getting(JvmTestSuite::class) {
            useJUnitJupiter()
        }

        val functionalTest by registering(JvmTestSuite::class) {
            dependencies {
                implementation(project())
            }

            targets {
                all {
                    testTask.configure { shouldRunAfter(test) } 
                }
            }
        }
    }
}

gradlePlugin {
    val greeting by plugins.creating {
        id = "org.example.greeting"
        implementationClass = "org.example.GradlePluginPlugin"
    }
}

gradlePlugin.testSourceSets.add(sourceSets["functionalTest"])

tasks.named<Task>("check") {
    dependsOn(testing.suites.named("functionalTest"))
}
+6 −7
Changes for .github/workflow-samples/gradle-plugin/plugin/src/functionalTest/java/org/example/GradlePluginPluginFunctionalTest.java: 6 added lines, 7 removed lines.
Original line number Diff line number Diff line
/*
 * This Java source file was generated by the Gradle 'init' task.
 * This source file was generated by the Gradle 'init' task
 */
package org.example.gradle.plugin;
package org.example;

import java.io.File;
import java.io.IOException;
@@ -15,7 +15,7 @@ import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.*;

/**
 * A simple functional test for the 'org.example.gradle.plugin.greeting' plugin.
 * A simple functional test for the 'org.example.greeting' plugin.
 */
class GradlePluginPluginFunctionalTest {
    @TempDir
@@ -29,24 +29,23 @@ class GradlePluginPluginFunctionalTest {
        return new File(projectDir, "settings.gradle");
    }

    @Test void canRunTaskWithGradle691() throws IOException {
    @Test void canRunTask() throws IOException {
        writeString(getSettingsFile(), "");
        writeString(getBuildFile(),
            "plugins {" +
            "  id('org.example.gradle.plugin.greeting')" +
            "  id('org.example.greeting')" +
            "}");

        // Run the build
        GradleRunner runner = GradleRunner.create();
        runner.forwardOutput();
        runner.withGradleVersion("6.9.1");
        runner.withPluginClasspath();
        runner.withArguments("greeting");
        runner.withProjectDir(projectDir);
        BuildResult result = runner.build();

        // Verify the result
        assertTrue(result.getOutput().contains("Hello from plugin 'org.example.gradle.plugin.greeting'"));
        assertTrue(result.getOutput().contains("Hello from plugin 'org.example.greeting'"));
    }

    private void writeString(File file, String string) throws IOException {
+3 −3
Changes for .github/workflow-samples/gradle-plugin/plugin/src/main/java/org/example/GradlePluginPlugin.java: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
/*
 * This Java source file was generated by the Gradle 'init' task.
 * This source file was generated by the Gradle 'init' task
 */
package org.example.gradle.plugin;
package org.example;

import org.gradle.api.Project;
import org.gradle.api.Plugin;
@@ -13,7 +13,7 @@ public class GradlePluginPlugin implements Plugin<Project> {
    public void apply(Project project) {
        // Register a task
        project.getTasks().register("greeting", task -> {
            task.doLast(s -> System.out.println("Hello from plugin 'org.example.gradle.plugin.greeting'"));
            task.doLast(s -> System.out.println("Hello from plugin 'org.example.greeting'"));
        });
    }
}
Loading