Skip to content

Commit 4cae870

Browse files
authored
Merge pull request #171 from gradle/tt/add-gradle-plugin-plugin-support
Add new ecosystem plugin and ST plugin for defining Gradle Plugin projects declaratively using Java
2 parents 21ba8de + a8afb29 commit 4cae870

File tree

13 files changed

+297
-7
lines changed

13 files changed

+297
-7
lines changed

unified-prototype/unified-plugin/plugin-android-init/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ testing {
2323
}
2424
}
2525

26-
tasks.getByPath("check").dependsOn(integTest)
26+
tasks.named("check") {
27+
dependsOn(integTest)
28+
}
2729
}
2830
}
2931

unified-prototype/unified-plugin/plugin-android/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ testing {
4545
}
4646
}
4747

48-
tasks.getByPath("check").dependsOn(integTest)
48+
tasks.named("check") {
49+
dependsOn(integTest)
50+
}
4951
}
5052
}
5153

unified-prototype/unified-plugin/plugin-common/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ description = "Common APIs and implementation classes shared by the ecosystem sp
1111

1212
dependencies {
1313
implementation("commons-io:commons-io:2.15.1")
14-
implementation(gradleApi())
1514
}
1615

1716
testing {
@@ -35,7 +34,9 @@ testing {
3534
}
3635
}
3736

38-
tasks.getByPath("check").dependsOn(integTest)
37+
tasks.named("check") {
38+
dependsOn(integTest)
39+
}
3940
}
4041
}
4142

unified-prototype/unified-plugin/plugin-jvm/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ description = "Implements the declarative JVM DSL prototype"
1111
dependencies {
1212
implementation(project(":plugin-common"))
1313
implementation("org.gradle.toolchains:foojay-resolver:0.8.0")
14-
implementation(gradleApi())
1514
}
1615

1716
testing {
@@ -25,7 +24,9 @@ testing {
2524
}
2625
}
2726

28-
tasks.getByPath("check").dependsOn(integTest)
27+
tasks.named("check") {
28+
dependsOn(integTest)
29+
}
2930
}
3031
}
3132

unified-prototype/unified-plugin/plugin-kmp/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ testing {
2828
}
2929
}
3030

31-
tasks.getByPath("check").dependsOn(integTest)
31+
tasks.named("check") {
32+
dependsOn(integTest)
33+
}
3234
}
3335
}
3436

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@file:Suppress("UnstableApiUsage")
2+
3+
plugins {
4+
`kotlin-dsl`
5+
id("build-logic.publishing")
6+
groovy // For spock testing
7+
}
8+
9+
description = "Implements the declarative Plugin building Plugin"
10+
11+
dependencies {
12+
implementation(project(":plugin-common"))
13+
implementation("org.gradle.toolchains:foojay-resolver:0.8.0")
14+
}
15+
16+
testing {
17+
suites {
18+
@Suppress("UnstableApiUsage")
19+
val integTest by registering(JvmTestSuite::class) {
20+
useSpock("2.2-groovy-3.0")
21+
22+
dependencies {
23+
implementation(project(":internal-testing-utils"))
24+
}
25+
}
26+
27+
tasks.named("check") {
28+
dependsOn(integTest)
29+
}
30+
}
31+
}
32+
33+
gradlePlugin {
34+
testSourceSets(project.sourceSets.getByName("integTest"))
35+
36+
plugins {
37+
create("gradle-plugin") {
38+
id = "org.gradle.experimental.java-gradle-plugin"
39+
displayName = "Gradle Java Plugin Experimental Declarative Plugin"
40+
description = "Experimental declarative plugin for building Gradle plugins in Java"
41+
implementationClass = "org.gradle.api.experimental.plugin.JavaGradlePluginPlugin"
42+
tags = setOf("declarative-gradle", "java", "plugin")
43+
}
44+
create("plugin-ecosystem") {
45+
id = "org.gradle.experimental.plugin-ecosystem"
46+
displayName = "Gradle Plugin Experimental Declarative Plugin"
47+
description = "Experimental declarative plugin for the building Gradle plugins"
48+
implementationClass = "org.gradle.api.experimental.plugin.GradlePluginEcosystemPlugin"
49+
tags = setOf("declarative-gradle", "plugin")
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package org.gradle.api.experimental.plugin
2+
3+
import org.gradle.test.fixtures.AbstractSpecification
4+
5+
/**
6+
* Integration tests for the Gradle plugin ecosystem's {@code javaGradlePlugin} plugin project type.
7+
* plugin project type.
8+
*/
9+
class JavaGradlePluginPluginSpec extends AbstractSpecification {
10+
def "gradle java plugin project builds"() {
11+
given:
12+
settingsFile << """
13+
plugins {
14+
id("org.gradle.experimental.plugin-ecosystem")
15+
}
16+
17+
dependencyResolutionManagement {
18+
repositories {
19+
mavenCentral()
20+
}
21+
}
22+
23+
rootProject.name = "example-plugin"
24+
"""
25+
26+
buildFile << """
27+
javaGradlePlugin {
28+
description = "An example project defining a Gradle plugin writen in Java"
29+
30+
dependencies {
31+
implementation("com.google.guava:guava:33.4.0-jre")
32+
}
33+
34+
registers {
35+
id("org.gradle.example") {
36+
description = "An example plugin"
37+
implementationClass = "org.gradle.example.ExamplePlugin"
38+
}
39+
}
40+
}
41+
"""
42+
43+
file("src/main/java/org/gradle/example/ExamplePlugin.java") << defineExamplePlugin()
44+
45+
expect:
46+
succeeds(":build")
47+
}
48+
49+
def "gradle java plugin project can be included and applied"() {
50+
given:
51+
settingsFile << """
52+
pluginManagement {
53+
includeBuild("plugin")
54+
}
55+
56+
include("example-project")
57+
58+
rootProject.name = "example-plugin-use"
59+
"""
60+
61+
and:
62+
file("example-project/build.gradle") << """
63+
plugins {
64+
id("org.gradle.example")
65+
}
66+
"""
67+
68+
and:
69+
file("plugin/build.gradle.dcl") << """
70+
javaGradlePlugin {
71+
description = "An example project defining a Gradle plugin writen in Java"
72+
73+
dependencies {
74+
implementation("com.google.guava:guava:33.4.0-jre")
75+
}
76+
77+
registers {
78+
id("org.gradle.example") {
79+
description = "An example plugin"
80+
implementationClass = "org.gradle.example.ExamplePlugin"
81+
}
82+
}
83+
}
84+
"""
85+
86+
file("plugin/src/main/java/org/gradle/example/ExamplePlugin.java") << defineExamplePlugin()
87+
file("plugin/settings.gradle.dcl") << defineExamplePluginSettings()
88+
89+
expect:
90+
succeeds(":example-project:help")
91+
result.getOutput().contains("Hello from ExamplePlugin")
92+
}
93+
94+
private String defineExamplePlugin() {
95+
return """
96+
package org.gradle.example;
97+
98+
import org.gradle.api.Plugin;
99+
import org.gradle.api.Project;
100+
101+
public class ExamplePlugin implements Plugin<Project> {
102+
@Override
103+
public void apply(Project project) {
104+
project.getLogger().lifecycle("Hello from ExamplePlugin");
105+
}
106+
}
107+
"""
108+
}
109+
110+
private String defineExamplePluginSettings() {
111+
return """
112+
plugins {
113+
id("org.gradle.experimental.plugin-ecosystem")
114+
}
115+
116+
dependencyResolutionManagement {
117+
repositories {
118+
mavenCentral()
119+
}
120+
}
121+
122+
rootProject.name = "example-plugin"
123+
"""
124+
}
125+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.gradle.api.experimental.plugin;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.initialization.Settings;
5+
import org.gradle.api.internal.plugins.software.RegistersSoftwareTypes;
6+
7+
@SuppressWarnings("UnstableApiUsage")
8+
@RegistersSoftwareTypes({JavaGradlePluginPlugin.class})
9+
public abstract class GradlePluginEcosystemPlugin implements Plugin<Settings> {
10+
@Override
11+
public void apply(Settings settings) {}
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.gradle.api.experimental.plugin;
2+
3+
import org.gradle.api.Action;
4+
import org.gradle.api.NamedDomainObjectContainer;
5+
import org.gradle.api.provider.Property;
6+
import org.gradle.api.tasks.Nested;
7+
import org.gradle.declarative.dsl.model.annotations.Configuring;
8+
import org.gradle.declarative.dsl.model.annotations.Restricted;
9+
10+
/**
11+
* The public DSL interface for a declarative Gradle Plugin.
12+
*/
13+
public interface JavaGradlePlugin {
14+
@Restricted
15+
Property<String> getDescription();
16+
17+
@Nested
18+
JavaGradlePluginDependencies getDependencies();
19+
20+
@Configuring
21+
default void dependencies(Action<? super JavaGradlePluginDependencies> action) {
22+
action.execute(getDependencies());
23+
}
24+
25+
NamedDomainObjectContainer<PluginRegistration> getRegisters();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.gradle.api.experimental.plugin;
2+
3+
import org.gradle.api.artifacts.dsl.Dependencies;
4+
import org.gradle.api.artifacts.dsl.DependencyCollector;
5+
import org.gradle.api.plugins.jvm.PlatformDependencyModifiers;
6+
7+
@SuppressWarnings("UnstableApiUsage")
8+
public interface JavaGradlePluginDependencies extends Dependencies, PlatformDependencyModifiers {
9+
DependencyCollector getApi();
10+
DependencyCollector getImplementation();
11+
}

0 commit comments

Comments
 (0)