diff --git a/src/main/paradox/settings.md b/src/main/paradox/settings.md index cd81572..4e3683c 100644 --- a/src/main/paradox/settings.md +++ b/src/main/paradox/settings.md @@ -26,4 +26,10 @@ The different levels of checking available are: * **Description:** Excludes the specified dependencies from the lockfile. * **Accepts:** `sbt.librarymanagement.ModuleFilter` -* **Default:** `DependencyFilter.fnToModuleFilter(_ => false)` (no exclusions) \ No newline at end of file +* **Default:** `DependencyFilter.fnToModuleFilter(_ => false)` (no exclusions) + +### dependencyLockConfigurationFilter + +* **Description:** Excludes the specified configurations from the lockfile. +* **Accepts:** `sbt.librarymanagement.ConfigurationFilter` +* **Default:** `DependencyFilter.fnToConfigurationFilter(_ => false)` (no exclusions) \ No newline at end of file diff --git a/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala b/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala index 5c07c9e..0955630 100644 --- a/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala +++ b/src/main/scala/software/purpledragon/sbt/lock/DependencyLockPlugin.scala @@ -19,7 +19,7 @@ package software.purpledragon.sbt.lock import sbt._ import sbt.Keys._ import sbt.internal.util.ManagedLogger -import sbt.librarymanagement.{DependencyFilter, ModuleFilter} +import sbt.librarymanagement.{DependencyFilter, ModuleFilter, ConfigurationFilter} import software.purpledragon.sbt.lock.DependencyLockUpdateMode._ import software.purpledragon.sbt.lock.model.{DependencyLockFile, LockFileMatches} import software.purpledragon.sbt.lock.util.MessageUtil @@ -32,6 +32,7 @@ object DependencyLockPlugin extends AutoPlugin { val dependencyLockWrite = taskKey[File]("write dependencies to lockfile") val dependencyLockRead = taskKey[Option[DependencyLockFile]]("read dependencies from lockfile") val dependencyLockModuleFilter = settingKey[ModuleFilter]("exclusion filter for dependencies") + val dependencyLockConfigurationFilter = settingKey[ConfigurationFilter]("exclusion filter for configurations") val dependencyLockCheck = taskKey[Unit]("check if dependency lock is up to date") @@ -51,8 +52,10 @@ object DependencyLockPlugin extends AutoPlugin { val dest = dependencyLockFile.value val updateReport = update.value val exclusionFilter = dependencyLockModuleFilter.value + val configFilter = dependencyLockConfigurationFilter.value + val configurations = thisProject.value.configurations.filterNot(c => configFilter(c)).map(_.toConfigRef) - val lockFile = DependencyUtils.resolve(updateReport, exclusionFilter, thisProject.value.configurations.map(_.toConfigRef)) + val lockFile = DependencyUtils.resolve(updateReport, exclusionFilter, configurations) val updateStatus = DependencyLockIO .readLockFile(dest) @@ -72,9 +75,11 @@ object DependencyLockPlugin extends AutoPlugin { val logger: ManagedLogger = streams.value.log val updateReport: UpdateReport = update.value val exclusionFilter = dependencyLockModuleFilter.value + val configFilter = dependencyLockConfigurationFilter.value + val configurations = thisProject.value.configurations.filterNot(c => configFilter(c)).map(_.toConfigRef) val currentFile = dependencyLockRead.value.getOrElse(sys.error(MessageUtil.formatMessage("lock.status.missing"))) - val updatedFile = DependencyUtils.resolve(updateReport, exclusionFilter, thisProject.value.configurations.map(_.toConfigRef)) + val updatedFile = DependencyUtils.resolve(updateReport, exclusionFilter, configurations) val changes = currentFile.findChanges(updatedFile) @@ -93,13 +98,15 @@ object DependencyLockPlugin extends AutoPlugin { val skipCheck = state.value.currentCommand.map(_.commandLine).exists(PluginTasks.contains) val checkMode = dependencyLockAutoCheck.value val exclusionFilter = dependencyLockModuleFilter.value + val configFilter = dependencyLockConfigurationFilter.value + val configurations = thisProject.value.configurations.filterNot(c => configFilter(c)).map(_.toConfigRef) if (checkMode != DependencyLockUpdateMode.CheckDisabled && !skipCheck) { logger.debug("Automatically checking lockfile") dependencyLockRead.value match { case Some(currentFile) => - val updatedFile = DependencyUtils.resolve(report, exclusionFilter, thisProject.value.configurations.map(_.toConfigRef)) + val updatedFile = DependencyUtils.resolve(report, exclusionFilter, configurations) val changes = currentFile.findChanges(updatedFile) @@ -136,6 +143,7 @@ object DependencyLockPlugin extends AutoPlugin { override def globalSettings: Seq[Def.Setting[_]] = Seq( dependencyLockAutoCheck := DependencyLockUpdateMode.WarnOnError, - dependencyLockModuleFilter := DependencyFilter.fnToModuleFilter(_ => false) + dependencyLockModuleFilter := DependencyFilter.fnToModuleFilter(_ => false), + dependencyLockConfigurationFilter := DependencyFilter.fnToConfigurationFilter(_ => false) ) } diff --git a/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/build.sbt b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/build.sbt new file mode 100644 index 0000000..578840c --- /dev/null +++ b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/build.sbt @@ -0,0 +1,9 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + "org.scalatest" %% "scalatest" % "3.0.8" % Test, +) + +// One ineffective filter and one for the Test scope. +dependencyLockConfigurationFilter := configurationFilter(name = "fake") | configurationFilter(name = "test") \ No newline at end of file diff --git a/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/build.sbt.lock b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/build.sbt.lock new file mode 100644 index 0000000..e8fb34a --- /dev/null +++ b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/build.sbt.lock @@ -0,0 +1,42 @@ +{ + "lockVersion" : 1, + "timestamp" : "2022-08-11T18:02:07.891395Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "compile", + "runtime" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/project/build.properties b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/project/build.properties new file mode 100644 index 0000000..22af262 --- /dev/null +++ b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.7.1 diff --git a/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/project/plugins.sbt b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/test b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/test new file mode 100644 index 0000000..1d6433e --- /dev/null +++ b/src/sbt-test/dependencyLockCheck/pass-with-config-exclusion/test @@ -0,0 +1 @@ +> dependencyLockCheck \ No newline at end of file diff --git a/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt new file mode 100644 index 0000000..578840c --- /dev/null +++ b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt @@ -0,0 +1,9 @@ +scalaVersion := "2.12.10" + +libraryDependencies ++= Seq( + "org.apache.commons" % "commons-lang3" % "3.9", + "org.scalatest" %% "scalatest" % "3.0.8" % Test, +) + +// One ineffective filter and one for the Test scope. +dependencyLockConfigurationFilter := configurationFilter(name = "fake") | configurationFilter(name = "test") \ No newline at end of file diff --git a/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt.lock b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt.lock new file mode 100644 index 0000000..e8fb34a --- /dev/null +++ b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt.lock @@ -0,0 +1,42 @@ +{ + "lockVersion" : 1, + "timestamp" : "2022-08-11T18:02:07.891395Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "compile", + "runtime" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt.lock.orig b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt.lock.orig new file mode 100644 index 0000000..e8fb34a --- /dev/null +++ b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/build.sbt.lock.orig @@ -0,0 +1,42 @@ +{ + "lockVersion" : 1, + "timestamp" : "2022-08-11T18:02:07.891395Z", + "configurations" : [ + "compile", + "optional", + "provided", + "runtime" + ], + "dependencies" : [ + { + "org" : "org.apache.commons", + "name" : "commons-lang3", + "version" : "3.9", + "artifacts" : [ + { + "name" : "commons-lang3.jar", + "hash" : "sha1:0122c7cee69b53ed4a7681c03d4ee4c0e2765da5" + } + ], + "configurations" : [ + "compile", + "runtime" + ] + }, + { + "org" : "org.scala-lang", + "name" : "scala-library", + "version" : "2.12.10", + "artifacts" : [ + { + "name" : "scala-library.jar", + "hash" : "sha1:3509860bc2e5b3da001ed45aca94ffbe5694dbda" + } + ], + "configurations" : [ + "compile", + "runtime" + ] + } + ] +} \ No newline at end of file diff --git a/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/project/plugins.sbt b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/project/plugins.sbt new file mode 100644 index 0000000..85547d6 --- /dev/null +++ b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/project/plugins.sbt @@ -0,0 +1,7 @@ +{ + val pluginVersion = System.getProperty("plugin.version") + if (pluginVersion == null) + throw new RuntimeException("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) + else addSbtPlugin("software.purpledragon" % "sbt-dependency-lock" % pluginVersion) +} diff --git a/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/test b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/test new file mode 100644 index 0000000..6dce62d --- /dev/null +++ b/src/sbt-test/dependencyLockWrite/unchanged-with-config-exclusion/test @@ -0,0 +1,3 @@ +> dependencyLockWrite +$ must-mirror build.sbt.lock build.sbt.lock.orig +> dependencyLockCheck \ No newline at end of file