|
| 1 | +# gradle-flatpak-sources |
| 2 | + |
| 3 | +[](https://github.com/meshtastic/gradle-flatpak-sources/actions/workflows/ci.yml) |
| 4 | +[](https://plugins.gradle.org/plugin/org.meshtastic.flatpak.sources.settings) |
| 5 | +[](COPYING) |
| 6 | +[](https://cla-assistant.io/meshtastic/gradle-flatpak-sources) |
| 7 | + |
| 8 | +A Gradle plugin that generates [Flathub-compliant](https://docs.flathub.org/docs/for-app-authors/requirements#no-network-access) offline dependency manifests (`flatpak-sources.json`) for Flatpak builds. |
| 9 | + |
| 10 | +## Quick Start |
| 11 | + |
| 12 | +Apply the settings plugin in `settings.gradle.kts` — it captures every dependency download from the very start of the build, with zero additional configuration: |
| 13 | + |
| 14 | +```kotlin |
| 15 | +// settings.gradle.kts |
| 16 | +plugins { |
| 17 | + id("org.meshtastic.flatpak.sources.settings") version "0.1.0" |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +Then generate the manifest using a fresh cache to force all artifacts to re-download: |
| 22 | + |
| 23 | +```bash |
| 24 | +./gradlew --no-build-cache --no-configuration-cache \ |
| 25 | + -Dgradle.user.home=/tmp/flatpak-gradle-home \ |
| 26 | + :app:assemble :captureFlatpakSources |
| 27 | +``` |
| 28 | + |
| 29 | +The output is written to `build/flatpak-sources.json` by default. |
| 30 | + |
| 31 | +## How It Works |
| 32 | + |
| 33 | +1. **Settings plugin** attaches a `BuildService` listener via [`BuildEventListenerRegistryInternal.onOperationCompletion`](https://github.com/gradle/gradle/blob/master/subprojects/build-events/src/main/java/org/gradle/internal/build/event/BuildEventListenerRegistryInternal.java) before any dependency resolution occurs — the same pattern as `gradle/github-dependency-graph-gradle-plugin`. It also back-fills URLs for artifacts resolved during `pluginManagement {}` (before the listener attached) by inspecting the already-resolved settings classpath. |
| 34 | + |
| 35 | +2. **`captureFlatpakSources` task** reads the captured URL set, locates each artifact in `caches/modules-2/files-2.1`, computes its SHA-256, and emits the manifest. If an artifact is not in the local cache it falls back to downloading and hashing it. |
| 36 | + |
| 37 | +3. **Output** follows the [Flatpak external data format](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest): `type: file`, `url`, `sha256`, `dest`, `dest-filename`, plus Maven Central mirror URLs for redundancy. |
| 38 | + |
| 39 | +## Included Builds (`build-logic/`) |
| 40 | + |
| 41 | +If your project uses an included build for convention plugins, apply the settings plugin there too — the plugin detects a pre-registered URL set and reuses it without creating a duplicate listener: |
| 42 | + |
| 43 | +```kotlin |
| 44 | +// build-logic/settings.gradle.kts |
| 45 | +plugins { |
| 46 | + id("org.meshtastic.flatpak.sources.settings") version "0.1.0" |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +## Use in Your Flatpak Manifest |
| 51 | + |
| 52 | +```yaml |
| 53 | +# org.example.myapp.yaml |
| 54 | +modules: |
| 55 | + - name: dependencies |
| 56 | + buildsystem: simple |
| 57 | + build-commands: ['true'] |
| 58 | + sources: |
| 59 | + - flatpak-sources.json |
| 60 | +``` |
| 61 | +
|
| 62 | +## Configuration |
| 63 | +
|
| 64 | +```kotlin |
| 65 | +flatpakSources { |
| 66 | + // Output file (default: build/flatpak-sources.json) |
| 67 | + outputFile.set(layout.buildDirectory.file("flatpak-sources.json")) |
| 68 | + |
| 69 | + // Destination prefix in Flatpak sandbox (default: "offline-repository") |
| 70 | + destPrefix.set("offline-repository") |
| 71 | + |
| 72 | + // Task paths that must complete before capture runs |
| 73 | + mustRunAfterTasks.set(listOf(":app:assemble")) |
| 74 | + |
| 75 | + // Generate Maven Central mirror URLs (default: true) |
| 76 | + generateMirrors.set(true) |
| 77 | + |
| 78 | + // URL suffixes to exclude (default: sources + javadoc jars) |
| 79 | + excludeSuffixes.set(setOf("-sources.jar", "-javadoc.jar")) |
| 80 | + |
| 81 | + // Force-resolve platform-specific native artifacts not resolved on the generation host. |
| 82 | + // Use when generating a Linux Flatpak manifest on macOS or Windows. |
| 83 | + targetPlatforms.set(setOf("linux-x64", "linux-arm64")) |
| 84 | + |
| 85 | + // Maven coordinate templates for each platform target ({platform} is substituted). |
| 86 | + platformDependencies.set(setOf( |
| 87 | + "org.jetbrains.skiko:skiko-awt-runtime-{platform}:0.144.6", |
| 88 | + "org.jetbrains.compose.desktop:desktop-jvm-{platform}:1.11.0", |
| 89 | + )) |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### Cross-Platform Artifact Resolution |
| 94 | + |
| 95 | +When building on macOS but targeting Linux Flatpak, platform-specific natives (Skiko renderers, Compose Desktop JARs, etc.) won't be resolved by Gradle's normal variant selection. `targetPlatforms` + `platformDependencies` forces them to download into the Gradle cache so they appear in the manifest: |
| 96 | + |
| 97 | +```kotlin |
| 98 | +flatpakSources { |
| 99 | + targetPlatforms.set(setOf("linux-x64", "linux-arm64")) |
| 100 | + platformDependencies.set(setOf( |
| 101 | + "org.jetbrains.skiko:skiko-awt-runtime-{platform}:0.144.6", |
| 102 | + )) |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## Requirements |
| 107 | + |
| 108 | +- **Gradle 9.0+** |
| 109 | +- **JDK 17+** |
| 110 | +- **`--no-configuration-cache`** — the capture mechanism uses runtime state that is not configuration-cache-safe |
| 111 | + |
| 112 | +## Internal APIs |
| 113 | + |
| 114 | +This plugin uses Gradle internal APIs (same trade-off as [flatpak-gradle-generator](https://github.com/flatpak/flatpak-gradle-generator)): |
| 115 | + |
| 116 | +- `org.gradle.internal.operations.BuildOperationListener` |
| 117 | +- `org.gradle.internal.resource.ExternalResourceReadBuildOperationType` |
| 118 | +- `org.gradle.internal.build.event.BuildEventListenerRegistryInternal` |
| 119 | + |
| 120 | +These APIs have been stable across Gradle 7–9. |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +Copyright (c) 2026 Meshtastic LLC. Licensed under [GPL-3.0-or-later](COPYING). |
| 125 | + |
| 126 | +## Contributing |
| 127 | + |
| 128 | +See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code style, and PR guidelines. |
0 commit comments