It appears that between 5.0 and 5.1, using a classifier when publishing JARs using the Maven Publishing plugin has been depreciated. I mention this because many of the fields are now marked deprecated in the v5.1 docs, but they were not in the v5.0 docs. I didn’t however see any mention of this deprecation in the v5.1 release notes, but perhaps I missed it.
What is the new way to specify a classifier when publishing JARs to Maven repos?
Note that the current version of the Maven Publishing Docs still list classifier in the complete example.
You are perfectly right, these changes happened in 5.1 but were not properly reflected in documentation.
In short, instead of classifier which is a simple field, you should use archiveClassifier which is a Property and thus enables Gradle to do more. For example if you were to set this value by using a task output, Gradle could infer the task dependency automatically. See javadoc for more features.
So all your code that is: classifier = 'foo'
needs to be changed to: archiveClassifier = 'foo' // DSL equivalent to archiveClassifier.set('foo')
For the Kotlin DSL, you have to do: archiveClassifier.set("sources")
There is no DSL sugar that allows to use the = for assigning a value to the property.
That limitation is due to a language level Kotlin limitation from what I can recall.
If that were to happen, one could also add an overload with an enum type for standard classifiers such as sources, javadoc, etc (so they can be discovered through the IDE while writing the task).