Skip to content

Commit a34f381

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. It reads the facts file the CLI writes (platforms/android/nativescript-gradle.json, schema in gradle-api/schema) and falls back to the rules CLIs up to 9.1 use when there is none, or when it no longer matches dependencies.json. 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 with AGP. Adds the gradle_api workflow: tests on changes, publishing to Maven Central on gradle-api-v* tags from the protected maven-central environment.
1 parent 226fd44 commit a34f381

45 files changed

Lines changed: 5013 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.

‎.github/workflows/gradle_api.yml‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: 'org.nativescript:gradle-api'
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- 'gradle-api/**'
8+
- 'vendor/gradle-plugin/**'
9+
- 'lib/services/android-plugin-build-service.ts'
10+
- 'lib/services/android-project-service.ts'
11+
- 'lib/services/android/**'
12+
- '.github/workflows/gradle_api.yml'
13+
push:
14+
branches: [ 'main' ]
15+
# Path filters do not apply to tag pushes.
16+
tags: [ 'gradle-api-v*' ]
17+
paths:
18+
- 'gradle-api/**'
19+
- 'vendor/gradle-plugin/**'
20+
- 'lib/services/android-plugin-build-service.ts'
21+
- 'lib/services/android-project-service.ts'
22+
- 'lib/services/android/**'
23+
- '.github/workflows/gradle_api.yml'
24+
25+
permissions:
26+
contents: read
27+
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.ref }}
30+
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
31+
32+
jobs:
33+
test:
34+
name: Test
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 45
37+
38+
steps:
39+
- name: Harden the runner (Audit all outbound calls)
40+
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
41+
with:
42+
egress-policy: audit
43+
44+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
45+
with:
46+
persist-credentials: false
47+
48+
- uses: gradle/actions/wrapper-validation@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
49+
with:
50+
# vendor/gradle-plugin/gradle/wrapper/gradle-wrapper.jar, which the CLI copies into
51+
# plugin builds, matches no published Gradle wrapper checksum.
52+
allow-checksums: 414142e6bc3b156908436f13b29e198bb3d59824f9c245ef145c809ddd5fe0a3
53+
54+
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
55+
with:
56+
distribution: temurin
57+
java-version: '17'
58+
59+
- uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
60+
with:
61+
cache-provider: basic
62+
# Done by the wrapper-validation step, which can allow the vendored jar.
63+
validate-wrappers: false
64+
65+
# The Android SDK preinstalled on the runner (ANDROID_HOME) enables the plugin build tests.
66+
- name: Check
67+
working-directory: gradle-api
68+
run: ./gradlew check --console=plain
69+
70+
publish:
71+
name: Publish to Maven Central
72+
if: startsWith(github.ref, 'refs/tags/gradle-api-v')
73+
needs: test
74+
runs-on: ubuntu-latest
75+
timeout-minutes: 30
76+
environment: maven-central
77+
78+
steps:
79+
- name: Harden the runner (Audit all outbound calls)
80+
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
81+
with:
82+
egress-policy: audit
83+
84+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
85+
with:
86+
persist-credentials: false
87+
88+
- uses: gradle/actions/wrapper-validation@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
89+
with:
90+
allow-checksums: 414142e6bc3b156908436f13b29e198bb3d59824f9c245ef145c809ddd5fe0a3
91+
92+
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
93+
with:
94+
distribution: temurin
95+
java-version: '17'
96+
97+
- uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
98+
with:
99+
cache-provider: basic
100+
cache-read-only: true
101+
validate-wrappers: false
102+
103+
- name: Check the tag matches the version
104+
working-directory: gradle-api
105+
env:
106+
TAG: ${{ github.ref_name }}
107+
run: |
108+
version="$(sed -n 's/^VERSION_NAME=//p' gradle.properties)"
109+
if [ "$TAG" != "gradle-api-v$version" ]; then
110+
echo "::error::Tag $TAG does not match VERSION_NAME=$version in gradle-api/gradle.properties"
111+
exit 1
112+
fi
113+
case "$version" in
114+
*-SNAPSHOT)
115+
echo "::error::$version is a snapshot version"
116+
exit 1
117+
;;
118+
esac
119+
120+
- name: Publish
121+
working-directory: gradle-api
122+
env:
123+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
124+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
125+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_CENTRAL_SIGNING_KEY }}
126+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_CENTRAL_SIGNING_KEY_PASSWORD }}
127+
run: |
128+
# The build skips signing without a key, which Maven Central would only reject later.
129+
for name in ORG_GRADLE_PROJECT_mavenCentralUsername ORG_GRADLE_PROJECT_mavenCentralPassword ORG_GRADLE_PROJECT_signingInMemoryKey; do
130+
if [ -z "${!name}" ]; then
131+
echo "::error::$name is empty; check the maven-central environment's secrets"
132+
exit 1
133+
fi
134+
done
135+
./gradlew publishAndReleaseToMavenCentral --no-configuration-cache --console=plain

‎.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

0 commit comments

Comments
 (0)