Skip to content

Conversation

@aldexis
Copy link
Contributor

@aldexis aldexis commented Oct 23, 2025

Before this PR

#1443 introduced two missing dependencies. However, because they were declared as implementation, this caused some setups to fail the checkUnusedDependencies tasks, in the case where there is metrics.yml file and thus no code to generate and use the dependencies (this setup exists in services that still generate the metrics.md file even if they themselves don't add new metrics)

After this PR

==COMMIT_MSG==
Do not declare project dependencies if there is no code to generate
==COMMIT_MSG==

It also turns out that metrics-core was actually part of the public API of the generated code, so I updated it to be declared as API rather than implementation.

Possible downsides?

@aldexis aldexis requested review from CRogers and FinlayRJW October 23, 2025 09:06
@changelog-app
Copy link

changelog-app bot commented Oct 23, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Do not declare project dependencies if there is no code to generate

Check the box to generate changelog(s)

  • Generate changelog entry


private static void configureProjectDependencies(Project project) {
project.getDependencies().add("api", "com.palantir.tritium:tritium-registry");
project.getDependencies().add("api", "com.palantir.safe-logging:preconditions");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this also should be an implementation dependency, but I didn't want to change it just here, due to it possibly already being used transitively in downstream projects.


configureProjectDependencies(project);
// Only add dependencies if we're going to generate code
if (!metricSchemaSourceDirectorySet.getFiles().isEmpty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure whether this is the proper way to do this. Is there a lazy way to do this with providers or something? (I wouldn't think so due to it being for dependency declaration, but checking just in case)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think because the whole configuration is setup above this should be fine, so long as nothing is dynamically generating sources at a later point?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initially feels not ideal to me, as it's checking where the files exist immediately at configuration time rather than being lazy as possible? It would be bad if this were generated code, perhaps acceptable if this is human authored code (not really sure without diving in metric-schema).

Anyway, the way to do this lazily is with this:

project.getDependencies().addProvider(...)

I'd honestly just do this as this is more likely to be correct.

Copy link
Contributor

@CRogers CRogers Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can't use that addProvider to conditionally not a dependency.

Instead you want:

project.getConfigurations().named("api", conf -> {
    conf.getDependencies().addAllLater(project.provider(() -> 
        /* return a list/set of dependencies made with project.getDependencies().create(...) */);
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking for manually-authored metrics.yml files in the custom sourceset that is defined above, containing the metrics definitions to generate code from, so this should be mostly ok.

@changelog-app
Copy link

changelog-app bot commented Oct 23, 2025

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

🐛 Fixes

  • Do not declare project dependencies if there is no code to generate (#1544)

@bulldozer-bot bulldozer-bot bot merged commit cf55229 into develop Oct 23, 2025
5 checks passed
@bulldozer-bot bulldozer-bot bot deleted the ald/exact-deps-no-codegen branch October 23, 2025 09:59
@autorelease3
Copy link

autorelease3 bot commented Oct 23, 2025

Released 0.35.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants