Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
222 stars 47 forks source link

Setting up maven publishing and release process #113

Closed ftomassetti closed 9 months ago

ftomassetti commented 9 months ago

Fix #109

To do:

ftomassetti commented 9 months ago

Some issues when checking for Maven Central requirements:

Screenshot 2023-12-07 at 13 53 41 Screenshot 2023-12-07 at 13 53 29 Screenshot 2023-12-07 at 13 53 20
lppedd commented 9 months ago

I see some MacOS stuff in there.
We know we are not building anything Mac-related as of now, what about just disabling Mac targets for now?

ftomassetti commented 9 months ago

I see some MacOS stuff in there. We know we are not building anything Mac-related as of now, what about just disabling Mac targets for now?

Well, we cannot build Mac-related stuff on the CI, but the release will be triggered only from my machines (as I have the credentials for Sonatype), and my machines are mac, so we can publish Mac-related stuff. I think we can skip it if necessary

ftomassetti commented 9 months ago

We are doing progress: the POM validation and the Signature validation are passing now.

Screenshot 2023-12-07 at 15 51 36

We still have issues with the Javadoc validation and with the sources validation (that was ok before).

Screenshot 2023-12-07 at 15 55 03
ftomassetti commented 9 months ago

Reading the message for the Sources and the Javadoc validation the problem seems to be actually the same, and that is that the main jar is not present, which has nothing to do with sources or javadoc.

The problem seems that those publications have a klib instead of a jar, and that makes Maven Central unhappy

Screenshot 2023-12-07 at 16 04 05
ftomassetti commented 9 months ago

By disabling JS and Native, I could publish on Maven Central the JVM module. Perhaps we can start with that and add an issue to fix at least the JS publication. As a test I just publish version 0.1.0-RC1, which should propagate to Maven Central in 20-30 minutes.

frett commented 9 months ago

hmm, it seems strange that klib wouldn't be supported, that's the standard publishing format for Kotlin Multiplatform.

okio is currently publishing klibs on maven central: https://repo1.maven.org/maven2/com/squareup/okio/okio-macosx64/3.6.0/

ftomassetti commented 9 months ago

Mmm, yes, they do not seem to be publishing jars (besides the metadata jar). I see they are using a different plugin than maven-publish (https://github.com/vanniktech/gradle-maven-publish-plugin). Maybe it is worth taking a look at what they are doing

lppedd commented 9 months ago

There is a chapter in the Multiplatform docs: https://kotlinlang.org/docs/multiplatform-publish-lib.html
One paragraph says:

Publications of a multiplatform library include an additional root publication kotlinMultiplatform that stands for the whole library and is automatically resolved to the appropriate platform-specific artifacts when added as a dependency to the common source set. Learn more about adding dependencies. This kotlinMultiplatform publication includes metadata artifacts and references the other publications as its variants.

And then:

Some repositories, such as Maven Central, require that the root module contains a JAR artifact without a classifier, for example kotlinMultiplatform-1.0.jar. The Kotlin Multiplatform plugin automatically produces the required artifact with the embedded metadata artifacts. This means you don't have to customize your build by adding an empty artifact to the root module of your library to meet the repository's requirements.

lppedd commented 9 months ago

I see you also added Dokka. IMO worth doing that in another PR if it's not strictly necessary here.

lppedd commented 9 months ago

I feel like configuring everything at the root should be enough, we shouldn't do anything with child modules.

ftomassetti commented 9 months ago

I see you also added Dokka. IMO worth doing that in another PR if it's not strictly necessary here.

We need to produce a javadoc jar to publish on Maven Central, and I am not sure we can do that without using Dokka, as we do not have java code

lppedd commented 9 months ago

Looks like you're right.

I've found this README for a publishing plugin aimed at being compatible with Kotlin Multiplatform, which has some explanation on publishing.

https://github.com/DanySK/publish-on-central/blob/master/README.md

lppedd commented 9 months ago

That plugin does indeed wrap Dokka. Might be a good pick to investigate. Maybe tagging the author might also help if we're stuck 👀

ftomassetti commented 9 months ago

Ok, if I understood correctly:

Now, the status is this looks good for Maven Central:

Screenshot 2023-12-08 at 09 24 18

However when I publish these locally and try them into an example the target works but the runtime does not. Gradle can resolve the dependency on the runtime, however no library is loaded in IDEA:

Screenshot 2023-12-08 at 09 25 45

I looked at the Jar being built for the runtime and it does not seem to contain classes:

Screenshot 2023-12-08 at 09 26 13

So I am not sure what is going on

ftomassetti commented 9 months ago

At least locally the problem seems to be solved by not publishing all the publications of the runtime but only the JVM one. I suspect otherwise a JAR from KMP replaces the "normal" JAR. By doing so I get a JAR that is ~400K instead of ~40K and I can have the example project (a JVM project and not a KMP project) works. I will verify that works only on Maven Central

ftomassetti commented 9 months ago

Ok, that was probably due to a line where I overridden the artifact name. Removing that line I can publish to Maven local and those publications work

ftomassetti commented 9 months ago

...and more problems:

  1. For some reason, now the publication are spread across 3 staging repositories
  2. The sources and javadoc validation fails for the JS publication, as the main jar artifact is missing
Screenshot 2023-12-08 at 10 23 23
lppedd commented 9 months ago

I'd give that Publish to Central plugin a try, because it seems maintaining the publication code will be a nightmare (if it's already a nightmare coming up with a working solution).

ftomassetti commented 9 months ago

I'd give that Publish to Central plugin a try, because it seems maintaining the publication code will be a nightmare (if it's already a nightmare coming up with a working solution).

I think that right now, we can get it working if we disable both native and JS when publishing on Maven Central. I am not even sure that JS users actually need the code on Maven Central. Maybe it is needed for KMP projects?

Regarding the Publish to Central plugin it states:

Unfortunatly, the Kotlin Multiplatform pre-initializes a sources jar, but not a javadoc jar, and Gradle does not allow to inspect the pom packaging or the artifact list without finalizing the publication (thus, preventing metadata to get generated).

Consequently, at the moment, the plugin only preconfigures the POM file and the signing.

I am not sure what that means. Maybe we then need to do something manually? If so, what?

ftomassetti commented 9 months ago

Let's see if on the Kotlin Slack they can give advice: https://kotlinlang.slack.com/archives/C3PQML5NU/p1702028532744219

lppedd commented 9 months ago

Unfortunately even JS consumers need a published package.

Regarding the plugin, I agree the explanation is a bit unclear. However there are sample projects under: https://github.com/DanySK/publish-on-central/tree/master?tab=readme-ov-file#kotlin-multiplatform-1

The template one has a seemingly straightforward configuration.

ftomassetti commented 9 months ago

I am trying out a similar plugin (com.vanniktech.maven.publish) and it seems to work... I just tried publishing version 0.1.0-RC5 with it. We could see if that works once it propagate to Maven Central

The plugin was suggested in some discussion on the Kotlin Slack group

ftomassetti commented 9 months ago

...and this seems to work!

I can run ./gradlew release --no-configuration-cache -Ptarget.is.native=false and have the tag created, commits pushed, the release done on Maven central (without any manual step) and the version updated automatically.

I also tested the version I released (0.1.0-RC5) and it works in the examples project

lppedd commented 9 months ago

Oh nice! I've seen that plugin seems to be quite popular.

I'll give a look at all the PR changes as soon as I'm back at home.

ftomassetti commented 9 months ago

I think we covered all the issues raised, so I am merging this. If there is anything else pending I can still cover it in a follow up ticket