Hi guys! I need guidance on how to deploy SNAPSHOT...
# library-development
s
Hi guys! I need guidance on how to deploy SNAPSHOT builds now that OSS doesn't allow creating new accounts? I have my account on Central and was created relatively recently. I want to publish SNAPSHOT versions of my project . The only way I could find is to contact Maven to get my lib published at OSS. I would appreciate any help.
m
There are no SNAPSHOTs with the new publishing flow, you'll have to host them somewhere else
s
Can you recommend any alternatives? I would love to have the experimental branch to be published as SNAPSHOT.
m
At Apollo, we started publishing nightly previews on Google Cloud Storage: https://github.com/apollographql/apollo-kotlin/blob/main/build-logic/src/main/kotlin/Publishing.kt#L371
I actually like that because, unlike SNAPSHOTs, you can control the retention of your artifacts
Builds using previews are more reproducable than SNAPSHOTs (until the artifacts are eventually removed)
Downside is it's another infra to maintain and it can have a cost if your repo is super popular. I think if you reach that point it's a good problem to have but still something to keep in mind
t
JitPack?
m
JitPack could work for SNAPSHOTs
s
Wow... Thanks for this. For my hobby library, I think this would be overkill 😅
I can't use JitPack as it doesn't support multiplatform projects yet.
🫤 1
m
For my hobby library, I think this would be overkill
It's not that hard really
GCS also has options to manage the retention automatically
s
I went through your
Publishing.kt
. Seems like there's lot for me to learn there 🙂. One last question from my side... How these SNAPSHOTs will be consumed? Which repository do need to declare? Any other setup needed?
m
Yea, don't look at
Publishing.kt
, there's way too much stuff in there 😅
Just look at the tweet for publishing. For consuming, it's just a maven repo: https://www.apollographql.com/docs/kotlin#previews
s
Oh got it. Thank u very much 👍
🙏 1
e
I'm worried this is going to be a big issue if a lot of libraries start doing this and I have to add a ton of custom repositories to my projects.
1
c
If you're using GitLab, you can publish to the built-in Maven registry from CI like this:
Copy code
// When running in GitLab CI, uses the auto-created CI variables to configure the GitLab Maven Registry.
// For more information on the variables and their values, see:
// - <https://docs.gitlab.com/ee/user/packages/maven_repository/>
// - <https://docs.gitlab.com/ee/ci/variables/predefined_variables.html>
publishing {
	repositories {
		val projectId = System.getenv("CI_PROJECT_ID") ?: return@repositories
		val token = System.getenv("CI_JOB_TOKEN") ?: return@repositories
		val api = System.getenv("CI_API_V4_URL") ?: return@repositories

		maven {
			name = "GitLab"
			url = uri("$api/projects/$projectId/packages/maven")

			credentials(HttpHeaderCredentials::class.java) {
				name = "Job-Token"
				value = token
			}

			authentication {
				create<HttpHeaderAuthentication>("header")
			}
		}
	}
}
@eygraber this should mostly be used for snapshots, keeping stable versions on Central, so you should very rarely need to commit any of these repositories.
e
What I like about Sonatype's current SNAPSHOT system is that I have one repo defined and now trying out a snapshot is just adding
-SNAPSHOT
to the version. I don't have to remember the repo url, add it to the project, etc...
1
c
is that true? I'm pretty sure you at least have to define the sonatype snapshots repository, which isn't just
mavenCentral()
e
Right, I meant that I only need to define a single snapshots repo.
Technically two, because of
s01
but it's constant.
☝️ 1