I still have issues with this: <https://gradle-com...
# plugin-development
s
I still have issues with this: https://gradle-community.slack.com/archives/CA745PZHN/p1710814982761129 is there any way I can have a compile dependency on internal gradle apis? because the class I want to use,
AbstractMavenPublisher
, isn't accessible when using
implementation(gradleApi())
(even though other internal classes are..?) for some reason
v
What do you mean exactly with "isn't accessible"? What error do you get where?
s
I am incapable of importing the class, as my IDE will not resolve it, even though I can navigate to it in the sources
my IDE renders it like this:
however, if I open
MavenRemotePublisher
, I can then navigate to it (it is a subclass of
AbstractMavenPublisher
oh, nvm, apparently it seems that this class is package-private
is there any way that it could possibly be exposed in an upcoming release? I need this so that I can implement the custom sonatype central publishing in a non-jank way
v
Unlikely, I'd say, it is an internal class :-)
s
because the issue I have is that I want to hook into the publishing to have it instead group all the artifacts together into a single zip file, before uploading it. and from what I can tell, the best way to do this would be to implement my own
MavenRepository
as well as a custom publisher for it that will create the artifacts, bundle them into a zip, and then upload that
v
How about instead registering a task that zips up those files and a task that uploads it?
s
yeah, but that would be relying on the implementation detail of how the files are generated from the task, which I'd prefer to avoid
v
And aren't there already plugins supporting the new system?
s
there are a few, but I didn't like them, so I'm looking to make my own
v
Why would it be depending on implementation detail?
s
because the plugins (or anyone in their buildscript) could change the directory structure they output their files in, no?
I'd much prefer to consume the
MavenArtifact
and then use that
which would require my own
MavenPublication
implementation, and then my own custom publisher
v
I did not say you should depend on files in the file system. Instead on the tasks that produce them. Always wire task outputs to task inputs
s
but then I'd need to depend on the file name, no? because I need a way to get the package its published to, the artifact name, etc. and since all that stuff is already in the pom, that seems the best way to get it
v
No, you shouldn't need file name. And artifacts I guess your task should be able to take from the publication configuration?
s
but the file needs to have a specific name, otherwise sonatype will reject it
it needs to be named in the same way it would be named as if it were published to a maven repo, so
[module]-[version]-[classifier].[extension]
(iirc)
and by default the
jar
task outputs in this format, however, I have noticed many projects before which will go and change this default behaviour to something else
v
So, as I said, take the information from the publication configuration and rename the file while packing the ZIP
s
thus, I can't rely on the file name of the jar from the
jar
task. so, I need some other way to get the module/version/classifier/extension and ensure the file has that name format. which is part of the
MavenArtifact
, as such it would be best to consume that
the publication config is associated directly with a specific publication, which itself is associated with a repository type, in this case a
MavenRepository
, so I'd have to either hijack an existing repository to publish to it, or have my own dummy repository that I hijack
v
As you seem to intend to make your plugin public, I don't think depending on any internal class is "best" as it always could break in any patch release
s
yes, however there is also no good api for this other than relying on workarounds, so I'm forced to use this so, it's a separate, optional, component of the plugin that is only enabled when a user requests it, which should prevent it from breaking in cases where it isn't used
so, I'm forced into implementing my own
MavenPublication
, and doing so requires the use of internal apis
v
Why do you need to implement your own
MavenPublication
. Can't you just process a configured
MavenPublication
? And if not, there is probably also no problem to even make an own
Publication
subclass that users could then configure. Or if you need all from
MavenPublication
plus some more, maybe a
MavenPublication
subclass.
s
because there is no way to tell a maven publication to "not upload files and then just give them to me so I can deal with them", so I need my own one
as for subclassing it, that's what I'm doing, and in order to subclass it and do what I want, I need to implement my own
MavenPublisher
, and all existing implementations of it use
AbstractMavenPublisher
, so I probably should as well so I can benefit from any code changes to it
ig a nasty solution I could use is to shove it in the
org.gradle.api.publish.maven.internal.publisher
package
v
because there is no way to tell a maven publication to "not upload files and then just give them to me so I can deal with them", so I need my own one
It's task that do it, so you could either replace the actions of those tasks by using
actions.clear()
(or
taskActions.clear()
, don't remember right now) and then registering own task actions with
doLast
or just leave the task without action.
Why do you need a
MavenPublisher
?
MavenPublication
does nowhere have
MavenPublisher
in its API, does it?
s
not in its public api, but the publishing plugin registers a
PublishToMavenRepository
task which uses a
MavenPublisher
, to perform the publication, so it's probably best for me to use that as well, to keep my code similar to gradle's
v
But you don't want to do a Maven publishing actually, you want to upload a zip to a URL. I guess you should just not try to use Maven publisher, but 🤷‍♂️
If you want such classes moved to the public API, you probably need to open a GitHub issue for that
s
I do kind of actually want to do maven publication. but I just need to zip the file before publishing it bc the internal structure of the zip is identical to that of a maven publication