diff --git a/project/JarExport.scala b/project/JarExport.scala index 947c3f374..7cd412e1a 100644 --- a/project/JarExport.scala +++ b/project/JarExport.scala @@ -3,6 +3,7 @@ import sbt.Keys.{crossTarget, fullClasspathAsJars} import sbt.{Compile, File, IO, Setting, TaskKey, SettingKey} +import java.nio.file.Path // Extending sbt.AutoPlugin causes this plugin to be automatically added to all sbt projects that match the triggers. // And because we don’t really specify any triggers, it is just added everywhere. @@ -14,17 +15,21 @@ object JarExport extends sbt.AutoPlugin { // though, it does not yet define behaviour val packageJars = TaskKey[File]("packageJars", "copies classpath jars to a file in the target dir") - val writeClasspathPath = SettingKey[File]("writeClasspathPath", "The file to write the classpath to.") + val packageJarsPath = SettingKey[String]("packageJarsPath", "The file to write the jars to.") + + val writeClasspathPath = SettingKey[String]("writeClasspathPath", "The file to write the classpath to.") // second additional command, same as the above val writeClasspath = TaskKey[File]("writeClasspath", "writes the classpath to a file in the target dir") // This defines settings the plugin makes. // It is essentially the same as if this was in a `.settings()` block in the build.sbt override lazy val projectSettings: Seq[Setting[?]] = Seq( + + packageJarsPath := crossTarget.value.toPath.resolve("jars").toString, // copy all jars required in the class path to a `jars` folder in the target directory packageJars := { val cp = (Compile / fullClasspathAsJars).value - val targetpath = crossTarget.value.toPath.resolve("jars") + val targetpath = Path.of(packageJarsPath.value) IO.delete(targetpath.toFile) IO.createDirectory(targetpath.toFile) cp.foreach { at => @@ -33,8 +38,8 @@ object JarExport extends sbt.AutoPlugin { // the return value is what `show stageJars` will display targetpath.toFile }, - writeClasspathPath := crossTarget.value.toPath.resolve("classpath.txt").toFile, + writeClasspathPath := crossTarget.value.toPath.resolve("classpath.txt").toString, // write the classpath into a file that can be passed to java as a commandline argument file writeClasspath := { val cp = (Compile / fullClasspathAsJars).value @@ -42,7 +47,7 @@ object JarExport extends sbt.AutoPlugin { val pathstring = at.data.toString.replace("\\", "/") s"""-cp "${pathstring}"\n""" }.mkString("") - val targetpath = writeClasspathPath.value.toPath + val targetpath = Path.of(writeClasspathPath.value) IO.write(targetpath.toFile, cpstring) targetpath.toFile }