You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ba25f09
Browse filesBrowse the repository at this point in the historyBrowse files
feat(gradle-api)!: settle the API before a stable release
- nativescript.projectDir is now projectRoot, so it can't be confused with
Gradle's own projectDir in include.gradle.
- PluginInfo no longer exposes aarName/aar; artifacts is the supported way to
use another plugin's binaries.
- self is null outside a plugin aar build, without needing facts.
- Facts require dependenciesJson.sha256 and minReaderSchemaVersion, and are
read through providers.fileContents so they are configuration inputs.
- has() capabilities follow a documented area.feature naming convention.
- A functional test puts two library versions in one build and checks the
higher one wins; the README warns against root classpaths, which would pin
a version for every plugin.
Copy file name to clipboardExpand all lines: gradle-api/README.md
+66-13Lines changed: 66 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,13 @@ Pin the **lowest** version that has what you need, never a range or `+`. Every p
64
64
the library to the same classpath and Gradle keeps the highest version, which is always backwards
65
65
compatible.
66
66
67
+
Add it **only** in `platforms/android/buildscript.gradle`, never on a root classpath: not in a
68
+
plugin's `rootbuildscript.gradle`, not in the app's `App_Resources/Android/rootbuildscript.gradle`,
69
+
and not in the root `build.gradle` of `platforms/android`. Gradle looks up classes in the root
70
+
project's class loader before the app's, so a version on the root classpath wins over every
71
+
plugin's `buildscript.gradle`, even one that asks for a newer version, and every plugin in the app
72
+
gets that older version.
73
+
67
74
**2. If you use `nativescript` in the app build**, apply the library at the top of
68
75
`platforms/android/include.gradle`. The whole file runs in the app build, including its
69
76
`repositories {}` and `dependencies {}` blocks; only code inside the `tempBuild` check of
@@ -124,10 +131,16 @@ never put a `buildscript {}` block in `include.gradle`.
124
131
| What your plugin needs | What it writes |
125
132
|---|---|
126
133
| Another plugin it lists in its `package.json``dependencies`| Nothing: in its own `.aar` build the CLI adds that plugin's `.aar`/`.jar` files as `implementation`, and in the app build every plugin is linked. |
127
-
| A plugin it doesn't list (typically `@nativescript/core`, usually a peer) |`compileOnly nativescript.plugin("...").artifacts` inside the `tempBuild` check, as in [the block above](#your-plugins-own-aar-build). Not `implementation`: Android's library plugin rejects a local `.aar` as `implementation` when it packages yours ("Direct local .aar file dependencies are not supported when building an AAR"), and the app links that plugin anyway. |
134
+
| A plugin it doesn't list (typically `@nativescript/core`, usually a peer) |`compileOnly nativescript.plugin("...").artifacts` inside the `tempBuild` check, as in [the block above](#your-plugins-own-aar-build), for the `.aar`/`.jar` files that plugin **ships prebuilt** in its package. Not `implementation`: Android's library plugin rejects a local `.aar` as `implementation` when it packages yours ("Direct local .aar file dependencies are not supported when building an AAR"), and the app links that plugin anyway. |
128
135
| Its own prebuilt `.jar`/`.aar`| Nothing, if they're in `platforms/android` or `platforms/android/libs`: the app build links them. |
129
136
| A Maven library | The usual `implementation "group:artifact:version"`. |
130
137
138
+
The CLI builds plugins' `.aar`s one after the other: `@nativescript/core` first, then every plugin
139
+
after the plugins it lists in its `dependencies`. The order between unrelated plugins is not
140
+
defined, and `artifacts` only includes an `.aar` once it exists, so on a clean build
141
+
`compileOnly nativescript.plugin(X).artifacts` can miss an `.aar` the CLI builds from X's sources.
142
+
If you need such an `.aar`, list X in your `dependencies`. `@nativescript/core` is always fine.
143
+
131
144
Never write `implementation files(...)` or `flatDir` pointing into another package or into
132
145
`node_modules`: the CLI decides where plugins' files are (see
133
146
[`pluginBuildLocation`](#for-app-developers-building-plugins-in-platformsandroid-opt-in)), and the
@@ -152,9 +165,9 @@ Known limits of the CLI's and runtime's templates today:
152
165
|`nativescript.apiLevel`| No | The API level of the library on the classpath. |
153
166
|`nativescript.pluginBuild`| No |`true` in the CLI's temporary build of some plugin's `.aar`. |
154
167
|`nativescript.isBuildingPlugin(String)`| No | Whether the plugin build is building that npm package. |
155
-
|`nativescript.has(String)`|Yes | Whether the CLI guarantees a capability. |
156
-
|`nativescript.self`| Yes |In a plugin build, the plugin being built (see below). `null` in the app build. |
157
-
|`nativescript.projectDir`| Yes | The NativeScript project root (the folder with the app's `package.json`). |
168
+
|`nativescript.self`|In a plugin build | In a plugin build, the plugin being built (see below). `null` in the app build, without reading the facts file. |
169
+
|`nativescript.has(String)`| Yes |Whether the CLI guarantees a capability (see [Capabilities](#capabilities)). |
170
+
|`nativescript.projectRoot`| Yes | The NativeScript project root (the folder with the app's `package.json`; `project.root` in the facts file). |
158
171
|`nativescript.appDir`| Yes | The app source folder (`appPath` in `nativescript.config`). |
|`nativescript.plugin(String)`| Yes | A plugin the CLI lists, by npm name. Throws if the app doesn't have it. |
@@ -163,7 +176,8 @@ Known limits of the CLI's and runtime's templates today:
163
176
|`nativescript.findPackage(String)`| Yes | Same, or `null`. |
164
177
165
178
"Needs facts" members read the facts file CLI 9.2+ writes, and throw one of the [errors](#errors)
166
-
below when it is missing or out of date. Without it, only the first three work.
179
+
below when it is missing or out of date. Without it, only the first three work, and `self` in the
180
+
app build.
167
181
168
182
A plugin (`PluginInfo`):
169
183
@@ -172,8 +186,7 @@ A plugin (`PluginInfo`):
172
186
|`name`| The npm package name. |
173
187
|`packageDir`| The installed package. Treat it as read-only. |
174
188
|`nativeDir`| Where Gradle reads the plugin's Android files from. |
175
-
|`artifacts`| Every `.aar` and `.jar` under `nativeDir`, as a lazy `FileCollection`. |
176
-
|`aarName`, `aar`| The name and location of the `.aar` the CLI builds from the plugin's sources (the file only exists if it has sources). |
189
+
|`artifacts`| Every `.aar` and `.jar` under `nativeDir`, as a lazy `FileCollection`. It includes the `.aar` the CLI builds from the plugin's sources once that exists (see [Depending on other plugins](#depending-on-other-plugins)). |
177
190
|`options`| Per-plugin options. Reserved; empty for now. |
178
191
179
192
`plugin` / `findPlugin` only know the plugins the CLI lists: packages that declare Android support
@@ -198,6 +211,12 @@ if (!nativescript.pluginBuild) {
198
211
that don't hoist (pnpm's default layout) may not resolve packages your app doesn't depend on
199
212
directly.
200
213
214
+
### Capabilities
215
+
216
+
`has(String)` answers from the facts file's `capabilities` list, which is empty today. Capability
217
+
names are dotted lowercase `area.feature` (for example `build.abis`). Once a CLI version lists a
218
+
capability, every later CLI lists it with the same meaning: names are only ever added.
219
+
201
220
## Errors
202
221
203
222
The library reads the facts file on the first use of a member that needs it, and stops the build
@@ -220,6 +239,18 @@ with one of these messages when it can't:
220
239
(Or, if `dependencies.json` is gone: "There is no `<…>/dependencies.json` next to the
221
240
NativeScript facts file `<…>`." followed by the same advice.)
222
241
242
+
-**Library too old for the facts file**, because the file's `minReaderSchemaVersion` is above the
243
+
schema version this library supports:
244
+
245
+
> The NativeScript facts file `<…>` needs org.nativescript:gradle-api supporting facts schema N,
246
+
> but this version of the library supports up to M. Update the plugins of this app that use
247
+
> org.nativescript:gradle-api: any one that pins a newer version of the library is enough.
248
+
249
+
-**Invalid facts file** ("Invalid NativeScript facts file `<…>`: …"), when a required field such as
250
+
`minReaderSchemaVersion` or `dependenciesJson.sha256` is missing or has the wrong type, or
251
+
`minReaderSchemaVersion` is greater than `schemaVersion`. The CLI
252
+
never writes such a file; prepare again.
253
+
223
254
## Recipes
224
255
225
256
**Compile against another plugin's Android library (e.g. core's widgets) in your own `.aar` build:**
@@ -251,7 +282,7 @@ repositories {
251
282
|| CLI 9.1 and older | CLI 9.2+ |
252
283
|---|---|---|
253
284
| Plugin not using the library | Unchanged | Its own `buildscript.gradle` also runs in its own `.aar` build |
254
-
| Plugin using the library, app build |`apiLevel`, `pluginBuild`and `isBuildingPlugin` work; anything else stops the build with the [no facts file](#errors) error | Facts from the CLI |
285
+
| Plugin using the library, app build |`apiLevel`, `pluginBuild`, `isBuildingPlugin`and `self` (null) work; anything else stops the build with the [no facts file](#errors) error | Facts from the CLI |
255
286
| Plugin using the library, its own `.aar` build | Library not loaded, so the [check](#your-plugins-own-aar-build) stops the build with the plugin's message (or, if a plugin it depends on applied the library, the [no facts file](#errors) error) | Library loaded and applied, facts from the CLI |
256
287
| Project prepared again by an older CLI after 9.2 | The [out-of-date facts file](#errors) error ||
257
288
@@ -321,6 +352,7 @@ built. The schema is [`schema/nativescript-gradle.schema.json`](schema/nativescr
@@ -341,6 +373,10 @@ built. The schema is [`schema/nativescript-gradle.schema.json`](schema/nativescr
341
373
```
342
374
343
375
- Paths are relative to the file, with forward slashes, so the folder can move.
376
+
-`minReaderSchemaVersion` is the lowest `schemaVersion` a reader must understand to use the file,
377
+
never above the file's own `schemaVersion`.
378
+
A library that supports only older schema versions refuses it (see [Errors](#errors)) instead of
379
+
reading part of it. CLI 9.2 writes `1`.
344
380
-`dependenciesJson.sha256` is the hash of the `dependencies.json` the CLI wrote next to it. A CLI
345
381
that doesn't know about this file (9.1 and older, e.g. a global one used by mistake) still
346
382
rewrites `dependencies.json` but leaves this file behind; the library notices the mismatch and
@@ -354,8 +390,10 @@ built. The schema is [`schema/nativescript-gradle.schema.json`](schema/nativescr
354
390
These are what keep old plugins working on new CLIs, and new plugins working on CLIs from 9.2 on.
355
391
356
392
**Facts file:** fields are only added. A field never changes meaning and is never removed.
357
-
`schemaVersion` goes up when fields are added; readers accept any version and read what they know.
358
-
Paths are relative. Anything a newer CLI does differently is expressed as data in the file, not as a
393
+
`schemaVersion` goes up when fields are added; readers accept any version and read what they know,
394
+
as long as it isn't below the file's `minReaderSchemaVersion`. A CLI raises `minReaderSchemaVersion`
395
+
only for a change that old readers would get wrong if they ignored it, which should be never: it is
396
+
the one way to tell libraries already published "you can't read this". Paths are relative. Anything a newer CLI does differently is expressed as data in the file, not as a
359
397
rule readers must know. A facts file that doesn't match the `dependencies.json` next to it is an
360
398
error, never used.
361
399
@@ -365,9 +403,12 @@ the CLI checks the facts file or a capability before relying on it. The library
365
403
366
404
## Releasing
367
405
368
-
Builds and tests run in `.github/workflows/gradle_api.yml`. Pushing a tag `gradle-api-v<version>`
369
-
that matches `VERSION_NAME` in `gradle.properties` publishes to Maven Central, from the protected
370
-
`maven-central` GitHub environment. It needs these environment secrets:
406
+
Builds and tests run in `.github/workflows/gradle_api.yml`, on Linux (unit and functional tests)
407
+
and Windows (unit tests). Pushing a tag `gradle-api-v<version>` on a commit of `main` that matches
408
+
`VERSION_NAME` in `gradle.properties` (not a `-SNAPSHOT`) publishes to Maven Central and releases
409
+
it at once, from the protected `maven-central` GitHub environment; the workflow refuses a tag on
410
+
any other commit. Give that environment required reviewers, since a Maven Central release can't be
411
+
undone. It needs these environment secrets:
371
412
372
413
-`MAVEN_CENTRAL_USERNAME`, `MAVEN_CENTRAL_PASSWORD`: a Central Portal user token with publishing
373
414
rights on the `org.nativescript` namespace.
@@ -386,3 +427,15 @@ cd gradle-api
386
427
./gradlew check # unit + functional tests (AGP tests need ANDROID_HOME)
387
428
./gradlew publishToMavenLocal # try it from a local app
388
429
```
430
+
431
+
### CLI release notes
432
+
433
+
CLI changes from this work that affect plugins that don't use the library, for the CLI 9.2 release
434
+
notes:
435
+
436
+
-**A plugin's own `platforms/android/buildscript.gradle` now also runs in that plugin's own `.aar`
437
+
build.** Before 9.2 it ran only in the app build and in the `.aar` builds of plugins that depend
438
+
on it. A plugin whose `buildscript.gradle` adds classpath dependencies or repositories now gets
439
+
them in its own build too. Check that it doesn't assume the app build (for example by reading
440
+
properties only the app's Gradle project sets); `project.hasProperty("tempBuild")` tells the two
Copy file name to clipboardExpand all lines: gradle-api/schema/nativescript-gradle.schema.json
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,15 @@
4
4
"title": "NativeScript Gradle facts",
5
5
"description": "Written by the NativeScript CLI at prepare time to platforms/android/nativescript-gradle.json and read by org.nativescript:gradle-api. Fields are only ever added: readers must ignore unknown fields, and a field never changes meaning. Every path is relative to the directory containing this file and uses forward slashes.",
"description": "Bumped only when a field is added. Readers accept any version and read the fields they know.",
10
+
"description": "Bumped only when a field is added. Readers accept any version that minReaderSchemaVersion allows them to, and read the fields they know.",
11
+
"type": "integer",
12
+
"minimum": 1
13
+
},
14
+
"minReaderSchemaVersion": {
15
+
"description": "The lowest schemaVersion a reader must support to read this file; never greater than schemaVersion. A reader that supports only a lower schema version must refuse the file, rather than read it partially.",
0 commit comments