gradle_dependencies
Select dependencies from declared Gradle module metadata in Starlark, or import checksum-pinned JARs from native lock state.
Description#
Declare requirements to let Struo select versions and variants from native metadata. With metadata_mode = "repository", graph actions acquire POMs, parent POMs, imported BOMs and redirected Gradle module metadata. The default declared mode reads explicit metadata files in srcs. Struo converges each configuration before emitting its artifacts and classpath. Neither mode runs a native dependency solver. Requirements and consumer attributes remain explicit in these modes. Restricted native mode evaluates a Gradle project to obtain declarations before Starlark selection, with the affected-query limitation described below.
Without requirements, Struo imports the closure from gradle.lockfile and gradle/verification-metadata.xml. Both files must be declared in srcs. This compatibility mode does not reconstruct native dependency edges or variant choices. Neither mode edits source files.
Each locked module becomes a maven_artifact target. Each selected configuration becomes a gradle_classpath target named <owner>.configuration.<configuration>. A Kotlin, Java, or Android consumer can depend on its selected classpath rather than an aggregate of every configuration. Its actions can start once those JARs are ready while unrelated artifacts are still downloading.
The lock records versions and configuration membership, not selected variants, artifact names, dependency edges, or classpath order. Verification metadata records verified files, not native artifact selection. Struo imports a single unambiguous verified JAR per module. When verification lists several archives, select the correct JAR explicitly through artifacts, using separate owners for configurations with different selections. For a platform or metadata redirect that native Gradle confirms has no archive, explicitly select an empty string. POM-only verification is not sufficient evidence that a module has no archive.
JARs stay whole, preserving signatures, multi-release entries and service descriptors. Each download is checksum-verified and cached through Struo's configured cache. Outputs use stable, relative per-target paths instead of Gradle's internal cache or the host Maven repository. In compatibility-import mode repositories are ordered mirrors for an already pinned file. Repository acquisition instead selects a component origin from native descriptors.
Declaration#
[[target]]
name = "deps"
kind = "gradle_dependencies"
srcs = ["gradle.lockfile", "gradle/verification-metadata.xml", "gradle/libs.versions.toml"]
[target.attrs]
configurations = ["compileClasspath", "runtimeClasspath"]
repositories = ["https://repo.maven.apache.org/maven2"]
[target.attrs.artifacts]
"com.squareup.okio:okio" = ""
[[target]]
name = "app"
kind = "kotlin_jvm_library"
srcs = ["src/main/kotlin/**/*.kt"]
[target.dependencies]
provided_deps = ["./deps.configuration.compileClasspath"]
runtime_deps = ["./deps.configuration.runtimeClasspath"]Attributes#
| Attribute | Type | Default | Description |
|---|---|---|---|
metadata_mode | string | declared | Read explicit metadata files, acquire metadata with repository, or evaluate restricted native declarations with native |
java_home | string | empty | Absolute Java 17 home for native declaration evaluation |
gradle_home | string | empty | Absolute Gradle 8.14.3 distribution home for native declaration evaluation |
metadata_refresh | string | empty | Required immutable observation generation in repository mode; change only for an authorized refresh |
metadata_cache_only | bool | false | Restore metadata observations without contacting repositories; fail on a missing observation |
requirements | map<string,list<any>> | {} | Native coordinates, group/module/version records, non-activating records with constraint = true, or { library = "alias" } and { bundle = "alias" } catalog references per configuration; enables Starlark selection |
module_metadata | map<string,string> | {} | Full coordinates to package-relative native .module files in srcs |
pom_metadata | map<string,string> | {} | Full coordinates to package-relative POMs in srcs, including required parents and imported BOMs |
configuration_attributes | map<string,any> | {} | Explicit consumer attributes per configuration; standard Java attributes use native compatibility and disambiguation |
lock_mode | string | locked | Selection enforces native pins and closure in locked mode; update computes a fresh selection without source writes |
lock_proposal | bool | false | Expose <owner>.lock-update to stage a guarded native lock creation or update; requires update mode and any existing lockfile in srcs |
remove_configurations | list<string> | [] | Explicit obsolete lock configurations to remove; removing the last one proposes lockfile deletion |
verification_additions | map<string,any> | {} | Reviewed SHA-256 pins keyed by full coordinate and artifact filename, published with the lock proposal |
lockfile | string | gradle.lockfile | Package-relative native lockfile |
verification_metadata | string | gradle/verification-metadata.xml | Native artifact verification inventory |
catalog | string | gradle/libs.versions.toml | Version catalog, required in srcs for catalog requirements or libraries |
libraries | list<string> | [] | Selected catalog aliases whose exact strict pins are checked against selected lock entries; does not narrow classpaths |
configurations | list<string> | all locked | Configurations to expose |
repositories | list<any> | Maven Central, Google | Ordered repository base URLs; repository mode also accepts normalized repository policy records |
artifacts | map<string,string> | {} | Selected JAR per group:name; empty string explicitly selects no archive |
artifact_urls | map<string,list<string>> | {} | URLs per group:name:version/file when native metadata assigns a different repository filename |
Starlark selection#
Repository acquisition uses the same declarations without explicit metadata maps:
[[target]]
name = "deps"
kind = "gradle_dependencies"
srcs = ["gradle.lockfile", "gradle/verification-metadata.xml"]
[target.attrs]
metadata_mode = "repository"
metadata_refresh = "reviewed-metadata-1"
requirements = { runtimeClasspath = ["example:library:1.0"] }
configuration_attributes = { runtimeClasspath = { "org.gradle.usage" = "java-runtime" } }
repositories = ["https://repo.maven.apache.org/maven2"]Metadata responses are bounded to 4 MiB and keyed by source, native verification trust, refresh generation and byte limit. Only HTTP 404 permits repository fallback; redirects and other errors fail. A POM redirects to .module only through Gradle's native publication comment. Each parent or BOM selects its own component origin; a component's POM model and artifacts stay at its selected origin rather than trying other repositories as mirrors. Normalized policies support content filters and POM/module source selection; artifact-derived metadata acquisition is unsupported.
Metadata observations require a conditional-create cache provider. Local caches, shared filesystem object stores and conditional-capable object stores provide that contract. HTTP caches without conditional creation fail closed. Cross-checkout recovery has been tested with a shared filesystem store, not a live cloud service. A new refresh generation permits a new observation; cache-only mode never refreshes on a miss. A retained observation whose body is missing fails instead of silently changing selection.
Configurations expand independently. A consumer can finish while an unrelated configuration's metadata is blocked. Within one configuration, Struo waits for version and variant convergence before fetching selected artifacts, so an early version cannot leak an evicted artifact into a build. Settled metadata definitions replay for read-only queries and affected tests without contacting repositories.
Native declarations#
metadata_mode = "native" runs a resolver-owned gradle_declarations producer before repository acquisition. Set java_home, gradle_home and an explicit list of configurations, and declare the build script, settings, properties and catalog inputs in srcs. Requirements, repositories and consumer attributes come from Gradle evaluation, not explicit selection overrides. Gradle never selects production dependencies; Starlark performs the subsequent metadata acquisition and selection.
Evaluation uses a fresh staged tree containing exactly the declared source bytes captured by graph loading. Removing a declared file removes it from the next staged tree. Relative file repositories inside the project retain their original source location rather than pointing into the staged tree. Native file repositories outside the project, including parent-relative and absolute external locations, fail explicitly; use repository mode with an absolute file URL for those repositories.
The declaration producer is uncached and runs again when building its graph. Read-only affected-test queries currently fail closed with deferred_graph_incomplete instead of returning a potentially incomplete test set. Read-only workspace confinement prevents source writes but does not establish complete executable observations, including non-filesystem channels. Explicit inputs and restricted read roots do not authorize replay. Repository-only declarations retain their separate settled-metadata replay support.
Pending lazy artifact-type attribute providers are unsupported. They can mutate repository or resolution policy while declarations are being captured, even when they return ordinary Java attribute values. The adapter rejects them without executing the provider. This does not prevent trusted build logic from realizing a provider earlier during project evaluation.
Native dependencyLocking { lockAllConfigurations() } and per-configuration activation support Gradle's DEFAULT and STRICT policies with the standard gradle.lockfile. Lenient locking, ignored dependencies and custom native lock locations fail explicitly. An active native lock cannot be replaced with a different Struo lockfile override. Struo's locked mode always requires complete state for every requested configuration, including an empty= entry for an empty closure. This is stricter than native DEFAULT, which permits a configuration without lock state. Explicit update mode selects afresh without applying old pins or changing either native file, including under native STRICT policy.
Pending lock-policy providers are rejected without evaluation. Their values can depend on which configuration's attributes native Gradle realizes first, so evaluating them in export order could choose a different lockfile or weaken the policy. Use fixed lock mode and file values and the default empty ignored-dependency property. A policy already finalized by trusted build logic remains eligible when it has no deferred side effects. Custom RegularFile values and backing File subclasses are unsupported, even after property finalization. Active native locking also requires fixed repository URL values of type String, URI or File; deferred providers and custom URL values are unsupported.
The exporter observes requested configuration hierarchies, collects outgoing capabilities, visits outgoing variants, realizes dependency attributes and captures repositories before finalizing lock policy. A lock-policy mutation during that realization fails explicitly, including when build logic catches setter exceptions. Struo does not infer a native resolution order across independently scheduled configurations.
Ordinary external dependencies.constraints declarations are inherited into each requested configuration. Their exact rich versions participate in selection without activating unused modules. Project, forced and attributed constraints fail explicitly. Constraint declarations are captured before lock-policy finalization and checked again before export. Locking activation is captured before lazy declarations are realized. Dependency records retain their original versions, attributes, exclusions and membership. A lazy constraint provider that changes these captured declarations fails instead of publishing a different selection from native Gradle.
The adapter requires Gradle 8.14.3, Java 17 and a single java-library project. It accepts catalog-backed external module declarations and ordinary Maven repository URLs. Applied scripts, buildscript dependencies, external plugins, buildSrc, composite builds, settings repositories, repository credentials and filters, custom resolution callbacks, substitutions, module replacements, artifact transforms and attribute rules fail explicitly. HTTP repositories require native allowInsecureProtocol. Native resolution APIs are prohibited, including artifact resolution queries. The action permits only local binding, denies network connections, confines writes to scratch space and has a 120-second invocation deadline. Build logic remains trusted executable code; the adapter is not a hostile-JVM security boundary.
Explicit lock updates#
In declared or repository mode, set lock_mode = "update" and lock_proposal = true, then build <owner>.lock-update. This stages gradle.lockfile and proposal.json as target outputs without modifying source files. Validate the proposal with struo edit sources --file <proposal> --outputs <target-output-directory> --check; omit --check only when ready to apply it. Native declaration mode rejects lock proposals before evaluation because executable build scripts can read inputs outside their declared snapshot. Staging supplied bytes does not establish complete publication provenance.
The proposal replaces only the selected configurations, preserving unrelated native configuration entries and empty configurations. It guards the exact original lock, verification, catalog and declared metadata bytes, together with configuration preimages captured by graph loading. A concurrent change rejects publication. Existing native lock state must be declared in srcs. A previously absent lockfile can be created only if it remains absent until application; check mode does not create it. remove_configurations removes only explicitly named obsolete configurations and may be used without requirements for cleanup. A selected configuration cannot also be removed. Removing the last configuration proposes deletion, not an empty locked configuration.
verification_additions supplies explicit reviewed pins, for example { "g:lib:1" = { "lib-1.jar" = { sha256 = "<64 hex digits>" } } }. Selection verifies against the proposed trust state, and <owner>.lock-update stages both native files in one guarded publication proposal. Existing verification policy, keys, ignored artifacts and unrelated checksums remain in the document. Existing checksum values cannot be replaced through this attribute. Downloading bytes never enrolls their hashes as trusted. Any existing verification file must be declared in srcs; an absent file uses an expected-absence guard. Its parent directory must already exist for explicit application. Rewriting may normalize XML formatting.
Declared metadata remains useful for offline fixtures:
[[target]]
name = "deps"
kind = "gradle_dependencies"
srcs = ["metadata/*.module", "gradle/verification-metadata.xml"]
[target.attrs]
lock_mode = "update"
requirements = { runtimeClasspath = ["example:library:1.0"] }
module_metadata = { "example:library:1.0" = "metadata/library-1.0.module" }
configuration_attributes = { runtimeClasspath = { "org.gradle.usage" = "java-runtime" } }Supply metadata for the reachable selected versions and conflict candidates, including transitive components. Struo merges exact requires, strictly, prefers and rejects version requirements, retracts edges from evicted versions, and applies variant dependency constraints only to reachable modules. A constraint alone does not introduce a module. Conflict selection compares native base versions before qualified versions and component release status. Each resulting configuration must have one selected version per module. Different configurations may select different versions or artifacts.
To declare a configuration constraint explicitly, add { group = "example", module = "library", version = { requires = "2.0" }, constraint = true } to its requirements. Constraints affect both direct and transitive dependencies, but do not contribute a classpath position or trigger metadata acquisition for an otherwise unused module. Constraint records support only group, module, version and optional reason; attributes, exclusions and catalog aliases are unsupported. The marker must be boolean; false retains ordinary dependency behavior.
Catalog requirements expand native library and bundle declarations in declaration order. They support version.ref and exact rich require, strictly, prefer and reject fields. A consulted catalog remains an affected-test input. Catalog references do not require the compatibility-mode libraries attribute.
When no .module file is declared for a component, pom_metadata supplies its Maven model. Struo reads parents by coordinates, ignores relativePath, inherits dependencies and properties, and applies imported BOM management with first-import precedence and local-entry replacement. Child properties affect parent management; imported BOMs retain their own property context. Ordinary library consumption uses management to default dependency versions, scopes and exclusions. Explicit org.gradle.category = "platform" consumption contributes management constraints without an archive or ordinary dependencies.
POM library views distinguish java-api and java-runtime, omitting optional, provided, test and system dependencies. Native Gradle derives these views when its JVM ecosystem plugins are active; an unconfigured native build may select the legacy default configuration instead. Exclusions remain path-scoped, including exclusions on platform constraints. An unexcluded path keeps a dependency reachable. Missing group or artifact fields in a POM exclusion mean *; an empty exclusion has no effect.
Missing component status defaults to integration. A strictly field replaces requires within the same rich-version request. Separate strict constraints and explicit rejections validate the selected conflict winner; rejecting a losing version does not fail resolution. With no required version, Struo chooses the highest non-rejected preference using Gradle's static version ordering.
Struo checks consumed .module and POM bytes against native verification metadata before reading their dependency edges. Metadata verification defaults to enabled, as in Gradle; this path requires a single SHA-256 pin per metadata file. An explicit native <verify-metadata>false</verify-metadata> disables that check. Artifact verification remains required. Struo reads artifact names and URLs from the selected variant, and a contradictory artifact checksum fails. Metadata-only variants can have an empty file list; a present file entry requires nonempty name and url strings. Selected artifact targets include variant and file identity so one configuration cannot substitute another's artifact. Configuration classpaths follow dependency traversal order; full native POM artifact-order parity remains unverified.
locked mode requires the selected configuration in gradle.lockfile, treats its versions as strict pins and rejects missing or obsolete components. update ignores the old selections, but retains existing artifact trust requirements. It does not enroll newly downloaded hashes or write either native file. libraries, artifacts and artifact_urls apply to compatibility import mode and fail if combined with selection requirements.
Standard Java variant matching follows Gradle's category, usage, JVM version, library elements, bundling and JVM environment precedence. Producers may omit requested attributes; a candidate covering strictly more requested attributes wins before disambiguation. Compatible JVM versions must not exceed the requested version, and the highest compatible version is preferred after usage selection. API consumers can fall back to runtime variants, and JARs can satisfy classes or resources requests. Unrequested categories prefer libraries, then regular platforms. Unsupported custom attribute rules are not inferred from metadata.
Selection supports one JAR or supported AAR per selected variant. Dynamic/range selectors, custom capabilities, component redirects and other dependency-level rules fail with diagnostics. Requests or producer variants carrying org.gradle.plugin.api-version also fail: native Gradle version compatibility and disambiguation are not approximated as exact attribute equality. Repeated selection states fail with gradle_resolution_cycle_unsupported; native cyclic conflict-history semantics, including a version that upgrades itself, remain unsupported. Other nonconverging graphs reach a bounded resolution limit.
Limits#
- Declared and repository modes do not evaluate Gradle build scripts, settings, plugins or repository rules. Native evaluation has the restrictions and affected-query limitation described above. In compatibility mode, generate native state with tasks that consume the required configurations and artifacts. A dependency report alone may not download the JARs needed for verification metadata.
- POM profiles, relocation and classifier/type overrides are unsupported. Declared POM redirects require explicitly declared module metadata; repository mode follows native publication markers. POM and verification XML use the bounded XML decoder, including numeric references, CDATA and comment-separated text. DTDs and external entities fail. Property expansion and dependency-context admission have explicit bounds. A
pom-packaged library still requires a trusted JAR; verification inventory alone does not prove native optional-archive absence. - Compatibility-import classpaths are coordinate-sorted; that mode cannot reconstruct native artifact order. Selection mode obtains its closure and order from module metadata.
- Compatibility import supports one JAR or supported AAR per module and owner. Selection supports one archive per selected variant. Timestamped SNAPSHOT discovery and buildscript locks are not supported.
- Supported AARs may omit
classes.jarand contain embeddedlibs/*.jar, assets and ABI-tagged native libraries. A deferred contents check rejects resource processing, manifest merging, consumer rules and unknown entries rather than discarding them. POM-derived AAR selection remains unsupported; AARs currently require compatibility import or explicit Gradle module metadata. - Only a single SHA-1, SHA-256 or SHA-512 checksum requirement per selected artifact is supported. Signature verification, other checksum algorithms, alternative checksums and multiple-algorithm policies fail explicitly rather than being weakened.
- Duplicate verification policy containers or switches and non-lowercase existing checksums fail before selection or trust updates. These inputs cannot be normalized implicitly because native Gradle may interpret them differently.
- Compatibility-mode catalog checks cover selected exact strict pins only. Selection-mode catalog requirements participate in version selection; neither mode establishes that the lock satisfies arbitrary build scripts.
- Changed lock, verification and consulted metadata paths conservatively select dependent tests, including direct artifact consumers. Selection retains consulted paths across resolution rounds, including metadata from evicted versions that influenced the winner. Per-entry test narrowing needs old/new graph comparison; fetch cache keys already use individual artifact pins instead of the whole lockfile.
The bundled gradle-dependencies-minimal starter runs Kotlin JUnit tests against native Gradle-generated lock state. Discover it with struo query schema gradle_dependencies.