Skip to content

Commit fbad714

Browse files
committed
feat(gradle-api): org.nativescript:gradle-api, a versioned Gradle API for plugins
A Java Gradle library (plugin id `org.nativescript.api`, extension `nativescript`) that plugins load from their buildscript.gradle and call from include.gradle instead of building paths into node_modules or the CLI's output folders: apiLevel, has(capability), pluginBuild, self, isBuildingPlugin(name), projectRoot, appDir, appResourcesDir, plugin(name) / findPlugin(name) and resolvePackage(name) / findPackage(name). It reads the facts file NativeScript CLI 9.2+ writes (platforms/android/nativescript-gradle.json, schema in gradle-api/schema). A missing facts file, or one that no longer matches dependencies.json, fails with a message that asks to prepare the project with CLI 9.2 or newer. Compiled for Java 11 against the Gradle 7.5 API; functional tests cover Gradle 7.5.1, 8.14.3 and 9.8.1, and run the CLI's plugin-build template and a frozen copy of the 9.1 one with AGP. The plugin-build template applies the library whenever a buildscript.gradle put it on the classpath, so the dependencies {} and repositories {} blocks the CLI copies from a plugin's include.gradle can use it in the plugin's own aar build.
1 parent 5a9a505 commit fbad714

51 files changed

Lines changed: 4735 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,9 @@ CLAUDE.local.md
131131
.env.*
132132
!.env.example
133133
.envrc
134+
135+
# org.nativescript:gradle-api
136+
gradle-api/build/
137+
gradle-api/**/.gradle/
138+
gradle-api/.kotlin/
139+
gradle-api/samples/**/build/

‎gradle-api/.gitattributes‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gradlew.bat text eol=crlf
2+
*.jar binary

‎gradle-api/README.md‎

Lines changed: 441 additions & 0 deletions
Large diffs are not rendered by default.

‎gradle-api/build.gradle.kts‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
plugins {
2+
`java-gradle-plugin`
3+
id("com.vanniktech.maven.publish") version "0.35.0"
4+
}
5+
6+
// Plugins on NativeScript Android runtimes back to 8.4 build with Gradle 7.5 on JDK 11.
7+
val oldestSupportedGradle = "7.5.1"
8+
val oldestSupportedJava = 11
9+
10+
tasks.withType<JavaCompile>().configureEach {
11+
options.release = oldestSupportedJava
12+
options.encoding = "UTF-8"
13+
options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror"))
14+
}
15+
16+
tasks.javadoc {
17+
(options as StandardJavadocDocletOptions).apply {
18+
encoding = "UTF-8"
19+
addStringOption("-release", oldestSupportedJava.toString())
20+
addBooleanOption("Xdoclint:all,-missing", true)
21+
}
22+
exclude("org/nativescript/gradle/internal/**")
23+
}
24+
25+
// java-gradle-plugin adds the running Gradle's API to `api`; compile against the oldest supported
26+
// one instead so that using anything newer fails here rather than in a user's build.
27+
configurations.named("api") {
28+
withDependencies { removeIf { it is FileCollectionDependency } }
29+
}
30+
31+
val functionalTest: SourceSet by sourceSets.creating
32+
33+
dependencies {
34+
compileOnly("dev.gradleplugins:gradle-api:$oldestSupportedGradle")
35+
36+
testImplementation(gradleApi())
37+
testImplementation(platform("org.junit:junit-bom:5.13.4"))
38+
testImplementation("org.junit.jupiter:junit-jupiter")
39+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
40+
41+
"functionalTestImplementation"(gradleTestKit())
42+
"functionalTestImplementation"(platform("org.junit:junit-bom:5.13.4"))
43+
"functionalTestImplementation"("org.junit.jupiter:junit-jupiter")
44+
"functionalTestRuntimeOnly"("org.junit.platform:junit-platform-launcher")
45+
}
46+
47+
gradlePlugin {
48+
plugins {
49+
create("nativescript") {
50+
id = "org.nativescript.api"
51+
implementationClass = "org.nativescript.gradle.NativeScriptPlugin"
52+
displayName = "NativeScript Gradle API"
53+
description = providers.gradleProperty("POM_DESCRIPTION").get()
54+
}
55+
}
56+
}
57+
58+
// Functional tests consume the library the way plugins do, from a Maven repository, so they see
59+
// the published metadata and the real buildscript class loader scoping.
60+
val testRepo = layout.buildDirectory.dir("test-repo")
61+
62+
publishing {
63+
repositories {
64+
maven {
65+
name = "testRepo"
66+
url = uri(testRepo)
67+
}
68+
}
69+
}
70+
71+
val cleanTestRepo by tasks.registering(Delete::class) {
72+
delete(testRepo)
73+
}
74+
75+
tasks.withType<PublishToMavenRepository>().configureEach {
76+
if (name.endsWith("ToTestRepoRepository")) {
77+
dependsOn(cleanTestRepo)
78+
}
79+
}
80+
81+
// A release version is signed with keys only the publish job has; the test repository needs none.
82+
tasks.withType<Sign>().configureEach {
83+
val signingKey = providers.gradleProperty("signingInMemoryKey")
84+
onlyIf("a signing key is configured") { signingKey.isPresent }
85+
}
86+
87+
tasks.withType<Test>().configureEach {
88+
useJUnitPlatform()
89+
testLogging {
90+
events("failed", "skipped")
91+
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
92+
}
93+
}
94+
95+
val functionalTestTask = tasks.register<Test>("functionalTest") {
96+
description = "Runs the TestKit tests against the library published to the test repository."
97+
group = LifecycleBasePlugin.VERIFICATION_GROUP
98+
testClassesDirs = functionalTest.output.classesDirs
99+
classpath = functionalTest.runtimeClasspath
100+
shouldRunAfter(tasks.test)
101+
102+
dependsOn("publishAllPublicationsToTestRepoRepository")
103+
// The repository itself differs on every publish: snapshot file names carry a timestamp.
104+
inputs.files(tasks.jar).withNormalizer(ClasspathNormalizer::class)
105+
inputs.dir("samples").withPathSensitivity(PathSensitivity.RELATIVE)
106+
inputs.dir("../vendor/gradle-plugin").withPathSensitivity(PathSensitivity.RELATIVE)
107+
108+
// Gradle 7.5 cannot run on JDK 21+, and TestKit starts its builds on the test JVM.
109+
javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(17) }
110+
111+
val androidHome = providers.environmentVariable("ANDROID_HOME")
112+
inputs.property("androidHomeSet", androidHome.map { true }.orElse(false))
113+
114+
systemProperty("nativescript.testRepo", testRepo.get().asFile.absolutePath)
115+
systemProperty("nativescript.libraryVersion", providers.gradleProperty("VERSION_NAME").get())
116+
systemProperty("nativescript.libraryJar", tasks.jar.get().archiveFile.get().asFile.absolutePath)
117+
systemProperty("nativescript.samplesDir", file("samples").absolutePath)
118+
systemProperty("nativescript.vendorGradlePluginDir", file("../vendor/gradle-plugin").absolutePath)
119+
val gradleVersions = providers.gradleProperty("functionalTestGradleVersions").orElse("7.5.1,8.14.3,9.8.1")
120+
inputs.property("gradleVersions", gradleVersions)
121+
systemProperty("nativescript.gradleVersions", gradleVersions.get())
122+
}
123+
124+
tasks.check {
125+
dependsOn(functionalTestTask)
126+
}

‎gradle-api/gradle.properties‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
org.gradle.caching=true
2+
org.gradle.configuration-cache=true
3+
4+
GROUP=org.nativescript
5+
POM_ARTIFACT_ID=gradle-api
6+
VERSION_NAME=0.1.0-SNAPSHOT
7+
8+
POM_NAME=NativeScript Gradle API
9+
POM_DESCRIPTION=Gradle API for NativeScript plugins: project paths, installed plugins and CLI capabilities, from the facts NativeScript CLI 9.2 and newer write.
10+
POM_INCEPTION_YEAR=2026
11+
POM_URL=https://github.com/NativeScript/nativescript-cli
12+
13+
POM_LICENSE_NAME=The Apache Software License, Version 2.0
14+
POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
15+
POM_LICENSE_DIST=repo
16+
17+
POM_SCM_URL=https://github.com/NativeScript/nativescript-cli
18+
POM_SCM_CONNECTION=scm:git:git://github.com/NativeScript/nativescript-cli.git
19+
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/NativeScript/nativescript-cli.git
20+
21+
POM_DEVELOPER_ID=nativescript
22+
POM_DEVELOPER_NAME=NativeScript team
23+
POM_DEVELOPER_URL=https://github.com/NativeScript
24+
25+
mavenCentralPublishing=true
26+
mavenCentralAutomaticPublishing=true
27+
signAllPublications=true
42.7 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
5+
networkTimeout=10000
6+
validateDistributionUrl=true
7+
zipStoreBase=GRADLE_USER_HOME
8+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)