xerial / sbt-sonatype

A sbt plugin for publishing Scala/Java projects to the Maven central.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sbt-sonatype 3 does not work with sbt-dynver

Atry opened this issue · comments

I use sbt-sonatype with sbt-dynver, to publish dynamic versions (e.g. 1.0.0+3-1234abcd ) to Maven Central.

Originally in sbt-sonatype 2.x, I used the command sbt ++$TRAVIS_SCALA_VERSION "sonatypeOpen \"Travis Job $TRAVIS_JOB_NAME $TRAVIS_JOB_NUMBER ($TRAVIS_JOB_WEB_URL)\"" publishSigned sonatypeRelease on Travis CI to publish a release.

After I upgrade sbt-sonatype to 3.4, I use the command sbt "set sonatypeSessionName := \"Travis Job $TRAVIS_JOB_NAME $TRAVIS_JOB_NUMBER ($TRAVIS_JOB_WEB_URL)\"" "set every publishTo := sonatypePublishToBundle.value" publishSigned sonatypeBundleRelease instead.

Unfortunately I got an error message of 400: Bad Request because sonatypePublishToBundle is sonatypeSnapshots, which does not support dynamic versions.

It seems Sonatype API rejects bundles that contain dynamic version files like project-1.0.0+3-1234abcd.jar.

In this case, we need to fall back to the previous step (it still works in sbt-sonatype 3.x):

  • Setting publishTo := sonatypePublishTo.value (for direct upload)
  • sonatypePrepare
  • +publishSigned
  • sonatypeReleaseAll

I'll look into more details to see if there is any workaround.

sbt-dynver set isSnapshot to true for dynamic versions, which do not end with -SNAPSHOT.

ah. OK. Then using isVersionStable will be more appropriate for sbt-dynver user.

You may be not willing to depend on sbt-dynver. Let's just check the version suffix. See #96

Ok. #96 is merged. The next step is to test whether the bundle can be uploaded properly.

ok. It seemed the comment #95 (comment) was my misunderstanding. I can properly upload artifacts that use sbt-dynver.

I'm releasing sbt-sonatype-3.6 with the fix in #96 now.

Thank you for the fix!

I just wonder if we could skip the snapshot version check for sonatypePublishToBundle, allowing for bundle uploading for any versions, no matter whether they end with -SNAPSHOT.

@xerial What do you think?

Uploading jars with -SNAPSHOT suffix is possible with bundle upload, but the validation will anyway fail. So there is no point in allowing that operation.

And also there seems no Sonatype API to upload snapshot versions as a bundle to Sonatype Snapshot repository.

Unfortunately, publish and publishSigned share the same publishTo setting, so returning None is not good for Snapshot releases.

As long as we ask users to use publishTo := sonatypePublishToBundle.value, returning None for this value would not work. Othewise, we need to ask users to set settings like this:

publishTo := {
   if(version.value.endsWith("-SNAPSHOT")) 
      Opts(Sonatype.snapshot..)
   else 
      Opts(local resolver to staging folder) 
}

It's a design choice and I prefer a simpler one. Advanced users just can specify a local staging folder or arbitrary snapshot repository for publishTo.

There are various types of build settings (including parallel build), which cannot be covered by a single task:
https://github.com/xerial/sbt-sonatype#advanced-build-settings

Some people (including your case #26) want to publish each sub-module individually to different sonatype profile, but majorities of the case would be aggregating all sub-modules artifacts into a single staging folder.

A tricky part is to tweak publish(Signed)To setting internally without explicitly modifying it. We need to use sbt commands, but sbt commands cannot be run for each project. So we need to use Tasks to define things like SonatypeBundleUploading task (or command). However, calling a task from commands also can be tricky code.

I think implementing it is too much (at least for me for now).

If sbt has a command like publishStaging and publishStagingAggregate, then the role of sbt-sonatype will be much simpler. (cc: @dwijnand, @eed3si9n)

You may be not willing to depend on sbt-dynver. Let's just check the version suffix. See #96

sbt identifies keys by structural equality.

So you can just define your own isVersionStable key and use it:

val isVersionStable = settingKey[Boolean]("")

// usage:
val result: Option[Boolean] = isVersionStable.?.value
// Using `?` in case sbt-dynver isn't present:
// None most probably means it's not