Does maven-publish have any way to write an arbitr...
# community-support
n
Does maven-publish have any way to write an arbitrary filename (e.g. a Python wheel) to the remote?
v
Without having it in the metadata, not even the Gradle module metadata? Add it as explicit
artifact(...)
to the publication. But most often it is better to define a feature variant, so that a Gradle consumer can resolve it using attribute-aware resolution
n
artifact()
seems to rename the file unconditionally
with python wheels, the file_name_ is significant, not just contents
t
I do not think there is an official supported way of doing this, but there is an internal API thats already known to be used elsewhere...
org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal#publishWithOriginalFileName
v
Ah, right, only the extension and classifier will survive, the rest is renamed to Maven Repository standard
<artifact>-<version>
@TheGoesen how would you use that internal method? I tried with
Copy code
(this as MavenPublicationInternal).publishWithOriginalFileName()
artifact(layout.projectDirectory.file("gradlew.bat"))
artifact(layout.projectDirectory.file("gradlew"))
but there was not any change, the names are like before. Or does it not work with
publishToMavenLocal
?
No, even with normal
publish
it does not have any effect
t
gradle native plugin does this:
Copy code
private void addPublicationsFromVariants(final Project project, final SoftwareComponentContainer components) {
    project.getPluginManager().withPlugin("maven-publish", plugin -> {
        components.withType(PublicationAwareComponent.class, component -> {
            project.getExtensions().configure(PublishingExtension.class, publishing -> {
                final ComponentWithVariants mainVariant = component.getMainPublication();
                publishing.getPublications().create("main", MavenPublication.class, publication -> {
                    MavenPublicationInternal publicationInternal = (MavenPublicationInternal) publication;
                    publicationInternal.getPom().getCoordinates().getArtifactId().set(component.getBaseName());
                    publicationInternal.from(mainVariant);
                    publicationInternal.publishWithOriginalFileName();
                });
it seems like a bit like its only gets spaghetied in if your going through the softwarecomponent api, not sure
v
I also tried with
Copy code
base {
    archivesName.set("foo")
}
and
Copy code
from(components["java"])
still no luck to get anything but the standard names in the repo 😕
t
hmm maybe it only works if you create your own software component? (with variants?) It has to work for the native plugin somehow..
v
Or in short, noone should really use that 😄
t
well if there would be a better way to support arbitrary filenames...
v
Probably by not using
maven-publish
? 🤷‍♂️
Aaah, for the actual files that option is totally irrelevant
It's only in the Gradle Module Metadata file
vs.
t
Ahh yes thats possible, in that case it "works" only if downloaded through gradle... so if you are downloading using gradle you can try to use this internal option, otherwise I think you have to unfurtuanatelly abandon maven-publish and write your own uploader...
v
Even when downloaded through Gradle, you also cannot simply use
artifact(...)
then, because that is exactly what it says, just uploads the artifact with that classifier and extension but does not contain any metadata. Because of that it should usually never be done. You really need to model the file then for example by adding a variant for it so that it will be part of the GMM.