Skip to content

Commit 6ffa208

Browse files
authored
Merge pull request #55 from gradle/am/swift
Add `swiftLibrary` and `swiftApplication` software types
2 parents a06590a + d1022bf commit 6ffa208

File tree

25 files changed

+231
-43
lines changed

25 files changed

+231
-43
lines changed

unified-prototype/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Declarative Gradle - Unified Plugin Prototypes
22

3-
This directory contains prototypes of plugins for JVM, Android, and KMP projects built using "unified" plugins that all utilize a similar model and are implemented using the Declarative DSL.
3+
This directory contains prototypes of plugins for JVM, Android, KMP and Swift projects built using "unified" plugins that all utilize a similar model and are implemented using the Declarative DSL.
44

55
Currently, these different ecosystems still apply distinct plugins, but those plugins all share a common `plugin-common` dependency, which will gradually grow to contain more functionality.
66

@@ -18,7 +18,7 @@ To run the application, use:
1818

1919
## JVM
2020

21-
Sample Java projects live in the `testbed-jvm-library` and `testbed-jvm-application` directories.
21+
Sample JVM projects live in the `testbed-jvm-library` and `testbed-jvm-application` directories.
2222

2323
These samples show the definition of a simple Java application and library that are implemented using a mix of Java 11 and Java 17 source code.
2424

@@ -40,9 +40,9 @@ To run the application, use:
4040
> ./gradlew testbed-kotlin-jvm-application:run
4141
```
4242

43-
## Kotlin KMP
43+
## Kotlin Multiplatform
4444

45-
The sample Kotlin Multiplatform project lives in the `testbed-kotlin-library` and `testbed-kotlin-application` directories.
45+
The sample Kotlin Multiplatform projects live in the `testbed-kotlin-library` and `testbed-kotlin-application` directories.
4646

4747
The `unified-prototype/plugin-kmp` plugin demonstrates creating extensions using the Declarative DSL, and loading the data from those extensions into the KMP project used by KGP.
4848

@@ -129,4 +129,8 @@ gradlew :testbed-android-application:assembleDebug
129129

130130
```shell
131131
gradlew :testbed-android-application:assembleRelease
132-
```
132+
```
133+
134+
## Swift
135+
136+
The sample Swift projects live in the `testbed-swift-library` and `testbed-swift-application` directories.

unified-prototype/settings.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ plugins {
1111
id("org.gradle.experimental.android-ecosystem")
1212
id("org.gradle.experimental.jvm-ecosystem")
1313
id("org.gradle.experimental.kmp-ecosystem")
14+
id("org.gradle.experimental.swift-ecosystem")
1415
}
1516

1617
dependencyResolutionManagement {
@@ -26,6 +27,7 @@ include("android-util")
2627
include("java-util")
2728
include("kotlin-jvm-util")
2829
include("kotlin-util")
30+
include("swift-util")
2931
include("testbed-android-library")
3032
include("testbed-android-application")
3133
include("testbed-kotlin-library")
@@ -36,3 +38,5 @@ include("testbed-jvm-library")
3638
include("testbed-jvm-application")
3739
include("testbed-java-application")
3840
include("testbed-java-library")
41+
include("testbed-swift-library")
42+
include("testbed-swift-application")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
swiftLibrary {
2+
swiftVersion = 5
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Utils {
2+
public let welcome = "Welcome to the swift-utils library!"
3+
4+
public init() {
5+
}
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
swiftApplication {
2+
swiftVersion = 5
3+
4+
dependencies {
5+
implementation(project(":swift-util"))
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Foundation
2+
import SwiftUtil
3+
4+
print("Hello from Swift")
5+
print(Utils().welcome)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
swiftLibrary {
2+
swiftVersion = 5
3+
4+
dependencies {
5+
implementation(project(":swift-util"))
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import SwiftUtil
2+
3+
class Lib {
4+
let utils = Utils()
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.gradle.api.experimental.common;
2+
3+
import org.gradle.api.Action;
4+
import org.gradle.api.tasks.Nested;
5+
import org.gradle.declarative.dsl.model.annotations.Configuring;
6+
import org.gradle.declarative.dsl.model.annotations.Restricted;
7+
8+
/**
9+
* Something that has application dependencies.
10+
*/
11+
@Restricted
12+
public interface HasApplicationDependencies {
13+
@Nested
14+
ApplicationDependencies getDependencies();
15+
16+
@Configuring
17+
default void dependencies(Action<? super ApplicationDependencies> action) {
18+
action.execute(getDependencies());
19+
}
20+
}

unified-prototype/unified-plugin/plugin-jvm/src/main/java/org/gradle/api/experimental/jvm/HasJvmLibrary.java renamed to unified-prototype/unified-plugin/plugin-common/src/main/java/org/gradle/api/experimental/common/HasLibraryDependencies.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
package org.gradle.api.experimental.jvm;
1+
package org.gradle.api.experimental.common;
22

33
import org.gradle.api.Action;
4-
import org.gradle.api.experimental.common.LibraryDependencies;
54
import org.gradle.api.tasks.Nested;
65
import org.gradle.declarative.dsl.model.annotations.Configuring;
76
import org.gradle.declarative.dsl.model.annotations.Restricted;
87

98
/**
10-
* Represents a library that runs on the JVM.
9+
* Something that has library dependencies.
1110
*/
1211
@Restricted
13-
public interface HasJvmLibrary {
12+
public interface HasLibraryDependencies {
1413
@Nested
1514
LibraryDependencies getDependencies();
1615

Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.gradle.api.experimental.java;
22

33
import org.gradle.api.experimental.jvm.HasJavaTarget;
4-
import org.gradle.api.experimental.jvm.HasJvmLibrary;
4+
import org.gradle.api.experimental.common.HasLibraryDependencies;
55
import org.gradle.declarative.dsl.model.annotations.Restricted;
66

77
/**
88
* A library implemented using a single version of Java.
99
*/
1010
@Restricted
11-
public interface JavaLibrary extends HasJavaTarget, HasJvmLibrary {
11+
public interface JavaLibrary extends HasJavaTarget, HasLibraryDependencies {
1212
}

unified-prototype/unified-plugin/plugin-jvm/src/main/java/org/gradle/api/experimental/jvm/HasJvmApplication.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.gradle.api.Action;
44
import org.gradle.api.experimental.common.ApplicationDependencies;
5+
import org.gradle.api.experimental.common.HasApplicationDependencies;
56
import org.gradle.api.provider.Property;
67
import org.gradle.api.tasks.Nested;
78
import org.gradle.declarative.dsl.model.annotations.Configuring;
@@ -11,15 +12,7 @@
1112
* Represents an application that runs on the JVM.
1213
*/
1314
@Restricted
14-
public interface HasJvmApplication {
15+
public interface HasJvmApplication extends HasApplicationDependencies {
1516
@Restricted
1617
Property<String> getMainClass();
17-
18-
@Nested
19-
ApplicationDependencies getDependencies();
20-
21-
@Configuring
22-
default void dependencies(Action<? super ApplicationDependencies> action) {
23-
action.execute(getDependencies());
24-
}
2518
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.gradle.api.experimental.jvm;
22

3+
import org.gradle.api.experimental.common.HasLibraryDependencies;
34
import org.gradle.declarative.dsl.model.annotations.Restricted;
45

56
/**
67
* A library that runs on the JVM and that is implemented using one or more versions of Java.
78
*/
89
@Restricted
9-
public interface JvmLibrary extends HasJavaTargets, HasJvmLibrary {
10+
public interface JvmLibrary extends HasJavaTargets, HasLibraryDependencies {
1011
}

unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kmp/KmpApplication.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.gradle.api.experimental.kmp;
22

33
import org.gradle.api.Action;
4-
import org.gradle.api.experimental.common.ApplicationDependencies;
4+
import org.gradle.api.experimental.common.HasApplicationDependencies;
55
import org.gradle.api.provider.Property;
66
import org.gradle.api.tasks.Input;
77
import org.gradle.api.tasks.Nested;
@@ -12,18 +12,10 @@
1212
* The public DSL interface for a declarative KMP application.
1313
*/
1414
@Restricted
15-
public interface KmpApplication {
15+
public interface KmpApplication extends HasApplicationDependencies {
1616
@Input
1717
Property<String> getLanguageVersion();
1818

19-
@Nested
20-
ApplicationDependencies getDependencies();
21-
22-
@Configuring
23-
default void dependencies(Action<? super ApplicationDependencies> action) {
24-
action.execute(getDependencies());
25-
}
26-
2719
@Nested
2820
KmpApplicationTargetContainer getTargets();
2921

unified-prototype/unified-plugin/plugin-kmp/src/main/java/org/gradle/api/experimental/kmp/KmpLibrary.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.gradle.api.experimental.kmp;
22

33
import org.gradle.api.Action;
4-
import org.gradle.api.experimental.common.LibraryDependencies;
4+
import org.gradle.api.experimental.common.HasLibraryDependencies;
55
import org.gradle.api.provider.Property;
66
import org.gradle.api.tasks.Input;
77
import org.gradle.api.tasks.Nested;
@@ -12,18 +12,10 @@
1212
* The public DSL interface for a declarative KMP library.
1313
*/
1414
@Restricted
15-
public interface KmpLibrary {
15+
public interface KmpLibrary extends HasLibraryDependencies {
1616
@Input
1717
Property<String> getLanguageVersion();
1818

19-
@Nested
20-
LibraryDependencies getDependencies();
21-
22-
@Configuring
23-
default void dependencies(Action<? super LibraryDependencies> action) {
24-
action.execute(getDependencies());
25-
}
26-
2719
@Nested
2820
KmpLibraryTargetContainer getTargets();
2921

Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.gradle.api.experimental.kotlin;
22

33
import org.gradle.api.experimental.jvm.HasJavaTarget;
4-
import org.gradle.api.experimental.jvm.HasJvmLibrary;
4+
import org.gradle.api.experimental.common.HasLibraryDependencies;
55
import org.gradle.declarative.dsl.model.annotations.Restricted;
66

77
/**
88
* A library implemented using Kotlin and that targets a single JVM version.
99
*/
1010
@Restricted
11-
public interface KotlinJvmLibrary extends HasJavaTarget, HasJvmLibrary {
11+
public interface KotlinJvmLibrary extends HasJavaTarget, HasLibraryDependencies {
1212
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
`kotlin-dsl`
3+
id("build-logic.publishing")
4+
}
5+
6+
description = "Implements the declarative Swift DSL prototype"
7+
8+
dependencies {
9+
implementation(project(":plugin-common"))
10+
}
11+
12+
gradlePlugin {
13+
plugins {
14+
create("swift-library") {
15+
id = "org.gradle.experimental.swift-library"
16+
implementationClass = "org.gradle.api.experimental.swift.StandaloneSwiftLibraryPlugin"
17+
tags = setOf("declarative-gradle")
18+
}
19+
create("swift-application") {
20+
id = "org.gradle.experimental.swift-application"
21+
implementationClass = "org.gradle.api.experimental.swift.StandaloneSwiftApplicationPlugin"
22+
tags = setOf("declarative-gradle")
23+
}
24+
create("swift-ecosystem") {
25+
id = "org.gradle.experimental.swift-ecosystem"
26+
implementationClass = "org.gradle.api.experimental.swift.SwiftEcosystemPlugin"
27+
tags = setOf("declarative-gradle")
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.gradle.api.experimental.swift;
2+
3+
import org.gradle.api.provider.Property;
4+
import org.gradle.declarative.dsl.model.annotations.Restricted;
5+
6+
@Restricted
7+
public interface HasSwiftTarget {
8+
@Restricted
9+
Property<Integer> getSwiftVersion();
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.gradle.api.experimental.swift;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.Project;
5+
import org.gradle.api.experimental.swift.internal.SwiftPluginSupport;
6+
import org.gradle.api.internal.plugins.software.SoftwareType;
7+
import org.gradle.language.swift.SwiftComponent;
8+
import org.gradle.language.swift.plugins.SwiftApplicationPlugin;
9+
10+
public abstract class StandaloneSwiftApplicationPlugin implements Plugin<Project> {
11+
@SoftwareType(name = "swiftApplication", modelPublicType = SwiftApplication.class)
12+
abstract public SwiftApplication getApplication();
13+
14+
@Override
15+
public void apply(Project project) {
16+
SwiftApplication application = getApplication();
17+
18+
project.getPlugins().apply(SwiftApplicationPlugin.class);
19+
20+
linkDslModelToPlugin(project, application);
21+
}
22+
23+
private void linkDslModelToPlugin(Project project, SwiftApplication application) {
24+
SwiftComponent model = project.getExtensions().getByType(SwiftComponent.class);
25+
SwiftPluginSupport.linkSwiftVersion(application, model);
26+
27+
model.getImplementationDependencies().getDependencies().addAllLater(application.getDependencies().getImplementation().getDependencies());
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.gradle.api.experimental.swift;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.Project;
5+
import org.gradle.api.experimental.swift.internal.SwiftPluginSupport;
6+
import org.gradle.api.internal.plugins.software.SoftwareType;
7+
import org.gradle.language.swift.plugins.SwiftLibraryPlugin;
8+
9+
public abstract class StandaloneSwiftLibraryPlugin implements Plugin<Project> {
10+
@SoftwareType(name = "swiftLibrary", modelPublicType = SwiftLibrary.class)
11+
abstract public SwiftLibrary getLibrary();
12+
13+
@Override
14+
public void apply(Project project) {
15+
SwiftLibrary library = getLibrary();
16+
17+
project.getPlugins().apply(SwiftLibraryPlugin.class);
18+
19+
linkDslModelToPlugin(project, library);
20+
}
21+
22+
private void linkDslModelToPlugin(Project project, SwiftLibrary library) {
23+
org.gradle.language.swift.SwiftLibrary model = project.getExtensions().getByType(org.gradle.language.swift.SwiftLibrary.class);
24+
SwiftPluginSupport.linkSwiftVersion(library, model);
25+
26+
model.getImplementationDependencies().getDependencies().addAllLater(library.getDependencies().getImplementation().getDependencies());
27+
model.getApiDependencies().getDependencies().addAllLater(library.getDependencies().getApi().getDependencies());
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.gradle.api.experimental.swift;
2+
3+
import org.gradle.api.experimental.common.HasApplicationDependencies;
4+
import org.gradle.declarative.dsl.model.annotations.Restricted;
5+
6+
@Restricted
7+
public interface SwiftApplication extends HasSwiftTarget, HasApplicationDependencies {
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.gradle.api.experimental.swift;
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+
@RegistersSoftwareTypes({
8+
StandaloneSwiftLibraryPlugin.class,
9+
StandaloneSwiftApplicationPlugin.class})
10+
public class SwiftEcosystemPlugin implements Plugin<Settings> {
11+
@Override
12+
public void apply(Settings target) {
13+
}
14+
}

0 commit comments

Comments
 (0)