diff --git a/README.md b/README.md index a4711e1..0887af1 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,26 @@ The following compatibility types are available: If no rules for a module are found in `versionPolicyDependencySchemes`, `versionPolicyDefaultScheme` is used as a compatibility type. Its default value is `VersionCompatibility.PackVer` (package versioning policy). +### Disable the tasks `versionPolicyCheck` or `versionCheck` on a specific project + +You can disable the tasks `versionPolicyCheck` and `versionCheck` at the +project level by using the `skip` key. + +By default, both `versionPolicyCheck / skip` and `versionCheck / skip` are +initialized to `(publish / skip).value`. So, to disable both tasks on +a given project, set the following: + +~~~ scala +publish / skip := true +~~~ + +Or, if you need more fine-grained control: + +~~~ scala +versionPolicyCheck / skip := true +versionCheck / skip := true +~~~ + ## Acknowledgments diff --git a/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicyPlugin.scala b/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicyPlugin.scala index 1b7c2ab..e9d6c65 100644 --- a/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicyPlugin.scala +++ b/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicyPlugin.scala @@ -31,6 +31,7 @@ object SbtVersionPolicyPlugin extends AutoPlugin { SbtVersionPolicySettings.updateSettings ++ SbtVersionPolicySettings.reconciliationSettings ++ SbtVersionPolicySettings.previousArtifactsSettings ++ - SbtVersionPolicySettings.findIssuesSettings + SbtVersionPolicySettings.findIssuesSettings ++ + SbtVersionPolicySettings.skipSettings } diff --git a/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala b/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala index c226966..4f5e6bc 100644 --- a/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala +++ b/sbt-version-policy/src/main/scala/sbtversionpolicy/SbtVersionPolicySettings.scala @@ -222,13 +222,15 @@ object SbtVersionPolicySettings { if (anyError) throw new Exception("Compatibility check failed (see messages above)") }, - versionCheck := { + versionCheck := Def.ifS((versionCheck / skip).toTask)(Def.task { + () + })(Def.task { val intention = versionPolicyIntention.?.value .getOrElse(throw new MessageOnlyException("Please set the key versionPolicyIntention to declare the compatibility guarantees of this release")) val versionValue = version.value - val s = streams.value - val projectId = thisProject.value.id + val s = streams.value + val projectId = thisProject.value.id if (Compatibility.isValidVersion(intention, versionValue)) { s.log.info(s"$projectId/$versionValue is a valid version number with respect to the compatibility guarantees '$intention'") @@ -238,11 +240,13 @@ object SbtVersionPolicySettings { else "You must increment the minor version number to publish a source incompatible release." throw new MessageOnlyException(s"$projectId/$versionValue is not a valid version number. $detail") } - }, - versionPolicyCheck := { + }).value, + versionPolicyCheck := Def.ifS((versionPolicyCheck / skip).toTask)(Def.task { + () + })(Def.task { val ignored1 = versionPolicyMimaCheck.value val ignored2 = versionPolicyReportDependencyIssues.value - }, + }).value, versionPolicyForwardCompatibilityCheck := { import MimaPlugin.autoImport._ val it = MimaIssues.forwardBinaryIssuesIterator.value @@ -288,6 +292,11 @@ object SbtVersionPolicySettings { }).value ) + def skipSettings = Seq( + versionCheck / skip := (publish / skip).value, + versionPolicyCheck / skip := (publish / skip).value + ) + def schemesGlobalSettings = Seq( versionPolicyDependencySchemes := Seq.empty, versionScheme := Some("early-semver") diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/build.sbt b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/build.sbt new file mode 100644 index 0000000..85df998 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/build.sbt @@ -0,0 +1,16 @@ +ThisBuild / organization := "com.example" +ThisBuild / scalaVersion := "2.13.2" + +val v100 = + project.in(file("v1-0-0")).settings( + name := "library-test-skip", + version := "1.0.0", + versionPolicyIntention := Compatibility.None + ) + +val v101 = + project.in(file("v1-0-1")).settings( + name := "library-test-skip", + version := "1.0.1", + versionPolicyIntention := Compatibility.BinaryCompatible + ) diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/project/plugins.sbt b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/project/plugins.sbt new file mode 100644 index 0000000..2843375 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % sys.props("plugin.version")) diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/test b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/test new file mode 100644 index 0000000..b1447dd --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/test @@ -0,0 +1,10 @@ +> v100/publishLocal +> reload + +-> v101/versionPolicyCheck +-> v101/versionCheck + +# If project is not published, no checks are performed and versionPolicyCheck and versionCheck succeed +> set v101/publish/skip := true +> v101/versionPolicyCheck +> v101/versionCheck diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/v1-0-0/src/main/scala/librarytest/LibraryTest.scala b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/v1-0-0/src/main/scala/librarytest/LibraryTest.scala new file mode 100644 index 0000000..1ddca93 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/v1-0-0/src/main/scala/librarytest/LibraryTest.scala @@ -0,0 +1,7 @@ +package librarytest + +trait Foo { + + def bar(x: Int): Int = x + +} diff --git a/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/v1-0-1/src/main/scala/librarytest/LibraryTest.scala b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/v1-0-1/src/main/scala/librarytest/LibraryTest.scala new file mode 100644 index 0000000..2d37144 --- /dev/null +++ b/sbt-version-policy/src/sbt-test/sbt-version-policy/skip-publish/v1-0-1/src/main/scala/librarytest/LibraryTest.scala @@ -0,0 +1,5 @@ +package librarytest + +trait Foo { + +}