Skip to content

refactor(oss-licenses): replace eager dependency resolution with lazy ArtifactView providers#381

Draft
timothyfroehlich wants to merge 2 commits intomainfrom
refactor-lazy-provider
Draft

refactor(oss-licenses): replace eager dependency resolution with lazy ArtifactView providers#381
timothyfroehlich wants to merge 2 commits intomainfrom
refactor-lazy-provider

Conversation

@timothyfroehlich
Copy link
Copy Markdown
Member

@timothyfroehlich timothyfroehlich commented Mar 10, 2026

Summary

This PR refactors the oss-licenses-plugin to fully support the Gradle Configuration Cache by replacing eager configuration-phase dependency resolution with lazy ArtifactView providers. It also introduces SHA-256 hashing for -SNAPSHOT dependencies to ensure license data remains fresh during active development.

Key Changes

  • Lazy ArtifactView Resolution: Moved dependency resolution from the configuration phase to the execution phase using lazy ArtifactView and resolvedArtifacts providers.
  • Configuration Cache Support:
    • Removed DependencyUtil and ArtifactFiles.
    • Rewrote property mapping to avoid capturing the Project object in closures by extracting necessary handlers (like DependencyHandler) into local variables. This avoids "cannot serialize object of type DefaultProject" errors.
    • Switched from @Nested MapProperty<String, ArtifactFiles> to isolated @Internal MapProperty<String, File> inputs to optimize hashing and ensure compatibility.
  • Snapshot Integrity: Added SHA-256 hashing for dependencies with -SNAPSHOT versions in DependencyTask. This hash is included in the dependencies.json report, forcing LicensesTask to re-run if a snapshot is re-published with changes.
  • Bug Fixes:
    • Fixed an incorrect reference to EMPTY_ARTIFACT (now ABSENT_ARTIFACT) in error messages.
    • Downgraded "POM file does not exist" logs from error to info to reduce noise from expected missing metadata in some libraries (e.g., androidx, org.jetbrains).
  • Improved Testing:
    • Added testSnapshotChangeTriggersExecution to verify the "Change Snapshot -> Re-run Task" cycle.
    • Added DependencyTaskTest.testAction_snapshotVersions_includeHashes to verify correct SHA-256 calculation.
    • Updated EndToEndTest.testConfigurationCache to assert that no configurations are resolved during the configuration phase.

Verification Results

  • All unit tests and E2E tests passed across multiple AGP versions (7.4 to 9.2-alpha).
  • Verified Configuration Cache compatibility with strict mode enabled (problems=fail).

@timothyfroehlich timothyfroehlich self-assigned this Mar 10, 2026
@timothyfroehlich timothyfroehlich force-pushed the refactor-lazy-provider branch 3 times, most recently from dff5638 to d84b4a3 Compare March 11, 2026 19:27
@timothyfroehlich timothyfroehlich force-pushed the refactor-lazy-provider branch 2 times, most recently from 66c7d5d to 64a11e5 Compare March 16, 2026 00:26
@timothyfroehlich timothyfroehlich changed the title refactor: return lazy Provider from DependencyUtil.resolveArtifacts refactor(oss-licenses): replace eager dependency resolution with lazy ArtifactView providers Mar 16, 2026
@timothyfroehlich
Copy link
Copy Markdown
Member Author

@liutikas I did a full rewrite to get things right and managed to significantly simplify things in the process. The Licenses task now separate arguments consisting of the runtimeConfiguration's resolvedArtifacts provider, with artifact resolution happening within the .map lambda. I also added a check in the configuration cache test to make sure we aren't resolving anything during configuration time.

I did use Gemini to help me get it straight, and had it add comments to help me (or other maintainers) remember for next time. I'm running an extra --scan now to double check things, but it should be pretty clean.

@liutikas
Copy link
Copy Markdown
Collaborator

I'm out of office for a week. I'll review this when I get back

@timothyfroehlich timothyfroehlich marked this pull request as draft March 17, 2026 19:48
@timothyfroehlich timothyfroehlich changed the base branch from main to testapp March 17, 2026 21:55
@timothyfroehlich timothyfroehlich changed the base branch from testapp to main April 15, 2026 21:06
… ArtifactView providers

- Shift resolution from configuration phase to execution phase using lazy ArtifactView providers.
- Improve Configuration Cache compatibility by avoiding Project object capture in closures.
- Fix ABSENT_ARTIFACT reference in error messages.
- Move POM missing warnings to info level.
- Add E2E test assertions to verify no configuration-time resolution.
…task re-execution

- Add SHA-256 hashing for -SNAPSHOT dependencies in DependencyTask.
- Wire artifact files to DependencyTask via a lazy MapProperty.
- Include the hash in the generated dependencies.json to trigger downstream task re-runs.
- Add unit and E2E tests to verify snapshot change detection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants