-
Notifications
You must be signed in to change notification settings - Fork 17
Add virtual platform constraint plugins for automatic version alignment across group modules #1436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
src/main/java/com/palantir/gradle/versions/VirtualPlatformSettingsPlugin.java
Outdated
Show resolved
Hide resolved
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 🔄 Changelog entries were re-generated at Wed, 29 Oct 2025 14:23:57 UTC!📋Changelog Preview💡 Improvements
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces virtual platform constraint plugins to enforce strict version alignment for all Java modules within the same group, addressing issues where modules might resolve to different versions due to transitive dependencies or downgrades.
Key changes:
- Adds
AddVirtualPlatformPluginto inject virtual platform constraints into published metadata - Adds
VirtualPlatformSettingsPluginto enforce version alignment during dependency resolution - Integrates the plugins into the existing consistent versions framework
Reviewed Changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
AddVirtualPlatformPlugin.java |
New plugin that injects virtual platform constraints when enabled via property |
VirtualPlatformSettingsPlugin.java |
New settings plugin that enforces alignment by reading metadata and assigning modules to virtual platforms |
ConsistentVersionsPlugin.java |
Integrates the new AddVirtualPlatformPlugin into the main plugin |
VersionsLockPlugin.java |
Makes isJavaLibrary method package-private for reuse |
AddVirtualPlatformPluginIntegrationSpec.groovy |
Integration tests for the AddVirtualPlatformPlugin |
VirtualPlatformSettingsPluginIntegrationSpec.groovy |
Comprehensive integration tests for the VirtualPlatformSettingsPlugin |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...test/groovy/com/palantir/gradle/versions/VirtualPlatformSettingsPluginIntegrationSpec.groovy
Outdated
Show resolved
Hide resolved
src/main/java/com/palantir/gradle/versions/VirtualPlatformSettingsPlugin.java
Outdated
Show resolved
Hide resolved
src/main/java/com/palantir/gradle/versions/AddVirtualPlatformPlugin.java
Outdated
Show resolved
Hide resolved
…ingsPlugin.java Co-authored-by: Copilot <[email protected]>
…lugin.java Co-authored-by: Copilot <[email protected]>
src/main/java/com/palantir/gradle/versions/ExternallyConsistentVersionsProducerPlugin.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| private void applyVirtualPlatformPerGroup(String groupName, Set<Project> projectGroup) { | ||
| String platformCoordinates = groupName + ":" + VIRTUAL_PLATFORM_NAME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the future we may want to have multiple external virtual platforms per repo. The clearest example of this could be a different platform for -api jars and non--api jars - I don't think they necessarily need to have the same version. We may never do this, but we should at least keep our options open with how we define this format.
Perhaps we could have the format consistent-versions.external-virtual-platform-com.maven.group:_ which gets converted to the virtual platform com.maven.group:_?
This means if we want to add multiple virtual platforms in the future, we could do this com.palantir.foo:_ and com.palantir.foo:_-api. This would replicate/be the same virtual platform as when people do this in their versions.props:
com.palantir.foo:* = 1.1.1
com.palantir.foo:*-api = 1.2.0We could always make a new "version" of the fake constraint (eg prefixed with consistent-versions.external-virtual-platform-v2 instead) but this makes us "forwards compatible" with all the power we currently have in versions.props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool I've switched over. I assume we will want to add some kind of extension that lets users create the platforms they want, then some logic in the producer plugin to only add the most specific platform constraint. Or can we add all the platform constraints that match the group and let gradle figure it out.
Say a user adds:
externalVirtualPlatforms {
platform("com.palantir.foo:*") {
version = "1.1.1"
}
platform("com.palantir.foo:*-api")
}say we are com.palantir.foo:bar-api would we add both a VP on com.palantir.foo:_:1.1.1 and com.palantir.foo:_-api:<latest-version> or just on the most specific?
| throw new IllegalStateException("AddVirtualPlatformPlugin must be applied to the root project"); | ||
| } | ||
|
|
||
| rootProject.afterEvaluate(project -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still configuration cacheable ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so - I've added a basic test
def "check does not break configuration cache"() {
expect:
runTasksWithConfigurationCache('--write-locks')
runTasksWithConfigurationCache('build')
}
Which I think would blow up if there where any configuration cache issues
src/main/java/com/palantir/gradle/versions/ExternallyConsistentVersionsProducerPlugin.java
Outdated
Show resolved
Hide resolved
…tVersionsProducerPlugin.java Co-authored-by: Claudia Rogoz <[email protected]>
Before this PR
Our builds do not currently guarantee that all modules within the same group (e.g.,
com.palantir:*) are resolved to the same version when used together—especially when multiple versions are present due to transitive dependencies or downgrades.Previous attempts (#1423) to add constraints via Gradle Module Metadata (GMM) improved this but did not fully enforce alignment, particularly during version downgrades.
After this PR
Solution:
Introduces a new "virtual platform" mechanism for strict version alignment of all Java modules within the same group, using a pair of new plugins:
ConstraintProducerPluginconsistent-versions.external-virtual-platform.com.palantir:_) into all Java modules in the group.ConstraintConsumerSettingsPlugin(published as thecom.palantir.externally-consistent-versionssettings plugin)settings.gradle.forceorstrictly.Tests:
Usage
Add to
settings.gradle:plugins { id 'com.palantir.externally-consistent-versions' version '<current version>' }Why Not Use BOMs?
==COMMIT_MSG==
Add virtual platform constraint plugins to enable automatic version alignment
ConstraintProducerPluginto inject a virtual platform constraint into all Java modules in a group.ConstraintConsumerSettingsPluginto enforce version alignment at dependency resolution time based on published POM.==COMMIT_MSG==
Possible Downsides