Skip to content

Potential refactor: Update.ForGroupId could enforce that all artifacts are genuinely for the same Maven group-id #3779

@rtyley

Description

@rtyley

this is a fairly minor issue, basically distracting/unclear to newcomer developers exploring the Scala Steward codebase

At the moment, Update.ForGroupId() takes a constructor parameter of multiple Update.ForArtifactIds, but within Update.ForGroupId there's nothing enforcing that all the Update.ForArtifactId's have the same Maven group-id:

final case class ForGroupId(
forArtifactIds: Nel[ForArtifactId]
) extends Single {

Due to the way Update.ForGroupIds are constructed, they will have the same Maven group-id:

def groupByGroupId(updates: List[ForArtifactId]): List[Single] = {
val groups0 =
updates.groupByNel(s => (s.groupId, s.currentVersion, s.newerVersions))
val groups1 = groups0.values.map { group =>
if (group.tail.isEmpty) group.head else ForGroupId(group)
}
groups1.toList.distinct.sorted
}

...but Update.ForGroupId itself doesn't guarantee it.

Within the class there are also parts like this, where we just assume the first group-id is the same for everything:

override def groupId: GroupId =
dependencies.head.groupId

Enforcement

  • Most easy: adding a require() statement inside Update.ForGroupId()
  • Trickier, but more type-worthy: change the constructor parameter so that it no longer takes Update.ForArtifactIds - instead, it allows just single fields for group-id, versions, etc, and a list of something - possibly ArtfactIds or CrossDependencys - that stores those multiple artifact ids. Note that Update instances are persisted, so changing the format of them will require updating the JSON decoders to be tolerant of both the old and new format.

Additional context

Here's a sketchy sketch of the Update type hierarchy we made while discussing this!

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions