Handy func: since and before
da-tubi opened this issue · 10 comments
Usually, a breaking API change happens on a specific version.
How about using since
and before
@enableIf(classpathMatchesArtifact(crossScalaBinaryVersion("spark-catalyst"), since("3.2.1")))
But I think it is too verbose, how about:
@enableIf(since(crossScalaBinaryVersion("spark-catalyst"), "3.2.1"))
@enableIf(before(crossScalaBinaryVersion("spark-catalyst"), "3.2.1"))
since
means>=
before
means<
Is there any existing library for comparing versions?
Version number could be extremely complicated to parse, and there are more than one standard, e.g. SemVer, PVP.
I think you may want to use this library https://javadoc.io/doc/org.apache.maven/maven-artifact/latest/org/apache/maven/artifact/versioning/package-summary.html
Here is an overview of version comparison: https://www.baeldung.com/java-comparing-versions
I think we need a library which has zero dependencies.
How about sbt.librarymanagement.VersionNumber#matchesSemVer
as https://stackoverflow.com/questions/14540503/comparing-versions-in-sbt indicated.
@ import $ivy.`org.scala-sbt::librarymanagement-core:1.6.1`
@ import sbt.librarymanagement.VersionNumber
import sbt.librarymanagement.VersionNumber
@ import sbt.librarymanagement.SemanticSelector
import sbt.librarymanagement.SemanticSelector
@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector(">=2.12"))
res3: Boolean = true
@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector(">2.12"))
res4: Boolean = false
@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector("<2.12"))
res5: Boolean = false
@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector("=2.12"))
res6: Boolean = true
Might be a better API:
@enableIf(matchesSemVer(crossScalaBinaryVersion("spark-catalyst"), ">=3.2.1"))
We may take the API from sbt and the IMPL from just-semver:
I think enableIf.scala should not depend on any of the libraries. Instead it would be good to let enableIf.scala provide a helper function that accepts a String => Bool
version predictor, while the users are free to use other libraries to create the predictor.
Note that when using a library with the @enableIf
annotation, you can use Provided
scope to avoid introducing the dependency to the runtime
libraryDependencies += "group-id" %% "artifact-id" % "version" % Provided