Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up maven publishing and release process #113

Merged
merged 23 commits into from
Dec 11, 2023
Merged

Conversation

ftomassetti
Copy link
Member

@ftomassetti ftomassetti commented Dec 7, 2023

Fix #109

To do:

@ftomassetti
Copy link
Member Author

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
Copy link
Contributor

lppedd commented Dec 7, 2023

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Contributor

frett commented Dec 7, 2023

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
Copy link
Member Author

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
Copy link
Contributor

lppedd commented Dec 7, 2023

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
Copy link
Contributor

lppedd commented Dec 7, 2023

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

@lppedd
Copy link
Contributor

lppedd commented Dec 7, 2023

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

@ftomassetti
Copy link
Member Author

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
Copy link
Contributor

lppedd commented Dec 7, 2023

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
Copy link
Contributor

lppedd commented Dec 7, 2023

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
Copy link
Member Author

Ok, if I understood correctly:

  • For the target (non multi-platform), we need to define the publications
  • For the runtime (multi-platform), we need to adjust the publications, which are auto-defined

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member Author

...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
Copy link
Contributor

lppedd commented Dec 8, 2023

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
Copy link
Member Author

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
Copy link
Member Author

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

@lppedd
Copy link
Contributor

lppedd commented Dec 8, 2023

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
Copy link
Member Author

ftomassetti commented Dec 8, 2023

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
Copy link
Member Author

...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
Copy link
Contributor

lppedd commented Dec 8, 2023

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 ftomassetti marked this pull request as ready for review December 8, 2023 11:15
settings.gradle.kts Outdated Show resolved Hide resolved
@ftomassetti
Copy link
Member Author

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

@ftomassetti ftomassetti merged commit 04d77aa into master Dec 11, 2023
3 checks passed
@ftomassetti ftomassetti deleted the mavenpublishing branch January 16, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish on Maven Central
3 participants