Giter Site home page Giter Site logo

Comments (15)

xerial avatar xerial commented on May 22, 2024 3

@dwijnand What Maven does is incrementing the suffix, -1, -2, ... to create unique SNAPSHOT versions. To do so we need to check the existing versions in the snapshot repository. But here, I think this is overkill as a feature of sbt-dynver.

OK. I'll check the code how can we add dynverUseSonatypeSnapshotVersion option.

from sbt-dynver.

leonardehrenfried avatar leonardehrenfried commented on May 22, 2024 1

@xerial I've used a slight variation of your code:

def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
  val prefix = out.ref.dropV.value
  val rev    = out.commitSuffix.mkString("+", "-", "")
  val dirty  = out.dirtySuffix.value

  val ver = (rev, dirty) match {
    case ("", "") =>
      prefix
    case (_, _) =>
      // (version)+(distance)-(rev)
      prefix + rev
  }
  val dynamicVersion = if (out.hasNoTags()) s"0.0.0-${out.version}" else ver
  val isSnapshot     = out.isSnapshot() || out.hasNoTags()
  if (isSnapshot) s"$dynamicVersion-SNAPSHOT" else dynamicVersion
}

This doesn't rely on an environment variable to figure out if something is a release or a snapshot.

I'm going to test this a little more, but I think it could be the basis for the sonatype mode.

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

Publishing to Sonatype staging repository works:

[info] 	published airframe-log_2.12 to https://oss.sonatype.org/service/local/staging/deploy/maven2/org/wvlet/airframe/airframe-log_2.12/0.33.1+2-338015a5/airframe-log_2.12-0.33.1+2-338015a5.pom

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

A workaround I found is, appending -SNAPSHOT to the version string:

def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
  val prefix = out.ref.dropV.value
  val suffix = out.commitSuffix.mkString("-", "-", "") + out.dirtySuffix.dropPlus.mkString("-", "")
  if(!suffix.isEmpty) {
    prefix + suffix + "-SNAPSHOT"
  }
  else {
    prefix
  }
}

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

According to Sonatype blog, the version file pattern is like this:

Pattern VERSION_FILE_PATTERN = Pattern.compile("^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$" );

http://blog.sonatype.com/2008/05/maven-code-how-to-detect-if-you-have-a-snapshot-version/

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

My current solution is like this:
https://github.com/wvlet/airframe/blob/58edb799062387d28e5940d7075c6e2c8e008e88/build.sbt#L19-L42

  • publish a sonatype friendly version (with -SNAPSHOT suffix) for each master commit to Sonatype snapshot repository.
  • For git tag release, switch the behavior using an environment variable (RELEASE=true) then use the default dynver string to use Sonatype releases repo.

It would be great if sbt-dynvar can generate sonatype-friendly version string by some setting. Do you accept such an PR?

from sbt-dynver.

dwijnand avatar dwijnand commented on May 22, 2024

Hey @xerial,

Thanks for opening the issue.

Given Sonatype's importance I think it would be good to make this use case work better out the box. The devil (as they say) is in the detail.

One (possibly ideal) idea would be to define whether or not the version contains -SNAPSHOT in terms of publishTo being or not being set to Sonatype snapshots, but I fear that that might lead into an infinite loop as it's very common to have if (isSnapshot.value) or if (version.value endsWith "-SNAPSHOT").

So perhaps we could just have a setting (i.e a SettingKey[Boolean]) that you can use to opt-in to Sonatype-friendly versions.

If we can't find a good solution there we can always resort to detailing Sonatype's expectations about version strings in the README..

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

We can also use datetime string like 20180104.091410-1 as well for Sonatype snapshot repo.

My idea is:

  • Extend dynver to use DateTime instead of Date to produce date + time (hh:mm:ss) string
  • (A) Add dynverUseSonatypeSnapshotVersion := true option

Then we can produce versions like this:

dynver version when (A) is true isSnapshot publishTo
0.1 0.1 false Sonatype Staging
0.1+5+0123abc 0.1+5-0123abc-SNAPSHOT true Sonatype Snapshot
0.1+5+0123abc-20180104-0914 0.1+5-0123abc-20180104.091410-1 true Sonatype Snapshot

@dwijnand If this is OK, I'll create a PR for this change.

from sbt-dynver.

dwijnand avatar dwijnand commented on May 22, 2024

Speaking of -SNAPSHOT things it might be good to also consider #52 when we do this change..

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

For #52,
Instead of using 0000000 (+0 commit), we should use the actual revision like:

1.0.0+0-xxxxxxx-20140707-1030

This is more informative to tell which git revision is used.

In this regard, 0.1+5-0123abc-SNAPSHOT also should have a timestamp, instead of -SNAPSHOT. For example:
0.1+5-0123abc-20180104.0914-0

We can use suffix -0 for distinguishing committed (-0) and non-committed (-1) timestamps.

from sbt-dynver.

dwijnand avatar dwijnand commented on May 22, 2024

For #52,
Instead of using 0000000 (+0 commit), we should use the actual revision like:

1.0.0+0-xxxxxxx-20140707-1030

This is more informative to tell which git revision is used.

Oh yes of course! Good idea.

In this regard, 0.1+5-0123abc-SNAPSHOT also should have a timestamp, instead of -SNAPSHOT. For example:
0.1+5-0123abc-20180104.0914-0

We can use suffix -0 for distinguishing committed (-0) and non-committed (-1) timestamps.

I think that's something that Maven repositories already do? I remember someone explaining that, but I never looked into it.

from sbt-dynver.

leonardehrenfried avatar leonardehrenfried commented on May 22, 2024

Is there an update on this? I would love this feature.

from sbt-dynver.

xerial avatar xerial commented on May 22, 2024

@leonardehrenfried I couldn't find a time for making a PR, but I guess the change would be simple.

from sbt-dynver.

leonardehrenfried avatar leonardehrenfried commented on May 22, 2024

This has probably been accidentally closed but is actually not resolved.

#64 fixes it though.

from sbt-dynver.

dwijnand avatar dwijnand commented on May 22, 2024

hehe

from sbt-dynver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.