Skip to content

Conversation

@shartte
Copy link
Contributor

@shartte shartte commented Jun 15, 2025

The Generic wildcard signatures for getPublishingMaven() and version are incorrect.

Remember the PECS shorthand from Effective Java... Producer Extends, Consumer Super. Paired with returning concrete types instead of wildcard types.

The Action passed to version consumes a VersionSpec and since it consumes it, the wildcard should be super. Reason: An action that consumes an Object is compatible, an action that only consumes specific subclasses of VersionSpec is not compatible (but our current signature simply ignores that).

The Action returned by getPublishingMaven cannot legally be used from Java code, since it's actually unknown what specific subtype of MavenRepository it supports. It has to either return Action<? super MavenRepository> or preferrably return the concrete type it supports.

This fixes this for consumers of the library:

var publications = project.getExtensions().getByType(PublishingExtension.class);
publications.getRepositories().maven(gradleUtilsExtension.getPublishingMaven()); // This currently does not compile

Since this is clearly a bug for consumers of the library, take that into consideration for deciding whether this is a breaking change ;-)
Anyone passing an Action<MySubclassOfVersionSpec> will already crash at runtime. And anyone respecting the Java type system cannot make use of getPublishingMaven.

@marchermans marchermans merged commit e0f1a47 into main Jun 15, 2025
1 check passed
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