@@ -140,12 +140,14 @@ object NativeImagePlugin extends AutoPlugin {
140140
141141 override lazy val projectSettings : Seq [Def .Setting [_]] = List (
142142 libraryDependencies += " org.scalameta" % " svm-subs" % " 101.0.0" ,
143- target.in(NativeImage ) := target.in(Compile ).value / " native-image" ,
144- target.in(NativeImageTest ) := target.in(Test ).value / " native-image-test" ,
145- target.in(NativeImageInternal ) :=
146- target.in(Compile ).value / " native-image-internal" ,
147- target.in(NativeImageTestInternal ) :=
148- target.in(Test ).value / " native-image-test-internal" ,
143+ NativeImage / target :=
144+ (Compile / target).value / " native-image" ,
145+ NativeImageTest / target :=
146+ (Test / target).value / " native-image-test" ,
147+ NativeImageInternal / target :=
148+ (Compile / target).value / " native-image-internal" ,
149+ NativeImageTestInternal / target :=
150+ (Test / target).value / " native-image-test-internal" ,
149151 nativeImageReady := {
150152 val s = streams.value
151153
@@ -163,15 +165,18 @@ object NativeImagePlugin extends AutoPlugin {
163165 nativeImageJvm := " graalvm-java11" ,
164166 nativeImageJvmIndex := " cs" ,
165167 nativeImageVersion := " 20.2.0" ,
166- name.in(NativeImage ) := name.value,
167- name.in(NativeImageTest ) := name.in(Test ).value,
168- mainClass.in(NativeImage ) := mainClass.in(Compile ).value,
169- mainClass.in(NativeImageTest ) := mainClass.in(Test ).value,
170- nativeImageOptions := List (),
168+ NativeImage / name := name.value,
169+ NativeImageTest / name :=
170+ (Test / name).value,
171+ NativeImage / mainClass :=
172+ (Compile / mainClass).value,
173+ NativeImageTest / mainClass :=
174+ (Test / mainClass).value,
175+ nativeImageOptions := List .empty,
171176 nativeImageTestOptions := nativeImageOptions.value,
172- nativeImageTestRunOptions := List () ,
177+ nativeImageTestRunOptions := List .empty ,
173178 nativeImageCoursier := {
174- val dir = target.in (NativeImageInternal ).value
179+ val dir = (NativeImageInternal / target ).value
175180 val out = copyResource(" coursier" , dir)
176181 if (Properties .isWin) {
177182 copyResource(" coursier.bat" , dir)
@@ -282,9 +287,9 @@ object NativeImagePlugin extends AutoPlugin {
282287 s " -agentlib:native-image-agent= $agentConfig= ${nativeImageAgentOutputDir.value}"
283288 val tpr = thisProjectRef.value
284289 val settings = Seq (
285- fork in ( tpr, Compile , run) := true ,
286- javaHome in ( tpr, Compile , run) := Some (graalHome),
287- javaOptions in ( tpr, Compile , run) += agentOption
290+ tpr / Compile / run / fork := true ,
291+ tpr / Compile / run / javaHome := Some (graalHome),
292+ tpr / Compile / run / javaOptions += agentOption
288293 )
289294 val state0 = state.value
290295 val extracted = Project .extract(state0)
@@ -297,7 +302,7 @@ object NativeImagePlugin extends AutoPlugin {
297302 arguments.mkString(" " )
298303 Project
299304 .extract(newState)
300- .runInputTask(run in ( tpr, Compile ) , input, newState)
305+ .runInputTask(tpr / Compile / run , input, newState)
301306 },
302307 nativeImageTestRunAgent := {
303308 val _ = nativeImageTestCommand.value
@@ -311,12 +316,12 @@ object NativeImagePlugin extends AutoPlugin {
311316 val agentOption =
312317 s " -agentlib:native-image-agent= $agentConfig= ${nativeImageTestAgentOutputDir.value}"
313318
314- val options = (javaOptions in ( Test , run) ).value ++ Seq (agentOption)
319+ val options = (Test / run / javaOptions ).value ++ Seq (agentOption)
315320
316- val __ = compile.in (Test ).value
317- val main = mainClass.in (NativeImageTest ).value
318- val cp = fullClasspath.in (Test ).value.map(_.data)
319- val manifest = target.in (NativeImageTestInternal ).value / " manifest.jar"
321+ val __ = (Test / compile ).value
322+ val main = (NativeImageTest / mainClass ).value
323+ val cp = (Test / fullClasspath ).value.map(_.data)
324+ val manifest = (NativeImageTestInternal / target ).value / " manifest.jar"
320325 manifest.getParentFile().mkdirs()
321326 createManifestJar(manifest, cp)
322327 val nativeClasspath = manifest.absolutePath
@@ -331,7 +336,7 @@ object NativeImagePlugin extends AutoPlugin {
331336 throw new MessageOnlyException (
332337 " no mainClass is specified for tests. " +
333338 " To fix this problem, update build.sbt to include the settings " +
334- " `mainClass.in( Test) := Some(\" com.MainTestClass\" )`"
339+ " `Test / mainClass := Some(\" com.MainTestClass\" )`"
335340 )
336341 )
337342 command ++= nativeImageTestRunOptions.value
@@ -344,12 +349,12 @@ object NativeImagePlugin extends AutoPlugin {
344349 }
345350 },
346351 nativeImageOutput :=
347- target.in (NativeImage ).value / name.in (NativeImage ).value,
352+ (NativeImage / target ).value / (NativeImage / name ).value,
348353 nativeImageTestOutput :=
349- target.in (NativeImageTest ).value / name.in (NativeImageTest ).value,
354+ (NativeImageTest / target ).value / (NativeImageTest / name ).value,
350355 nativeImageCopy := {
351356 val binary = nativeImage.value
352- val out = fileParser(baseDirectory.in (ThisBuild ).value).parsed
357+ val out = fileParser((ThisBuild / baseDirectory ).value).parsed
353358 Files .copy(
354359 binary.toPath(),
355360 out.toPath(),
@@ -384,17 +389,17 @@ object NativeImagePlugin extends AutoPlugin {
384389 }
385390 },
386391 nativeImage := {
387- val _ = compile.in (Compile ).value
388- val main = mainClass.in (NativeImage ).value
392+ val _ = (Compile / compile ).value
393+ val main = (NativeImage / mainClass ).value
389394 val binaryName = nativeImageOutput.value
390- val cp = fullClasspath.in (Compile ).value.map(_.data)
395+ val cp = (Compile / fullClasspath ).value.map(_.data)
391396 // NOTE(olafur): we pass in a manifest jar instead of the full classpath
392397 // for two reasons:
393398 // * large classpaths quickly hit on the "argument list too large"
394399 // error, especially on Windows.
395400 // * we print the full command to the console and the manifest jar makes
396401 // it more readable and easier to copy-paste.
397- val manifest = target.in (NativeImageInternal ).value / " manifest.jar"
402+ val manifest = (NativeImageInternal / target ).value / " manifest.jar"
398403 manifest.getParentFile().mkdirs()
399404 createManifestJar(manifest, cp)
400405 val nativeClasspath = manifest.absolutePath
@@ -410,14 +415,14 @@ object NativeImagePlugin extends AutoPlugin {
410415 throw new MessageOnlyException (
411416 " no mainClass is specified. " +
412417 " To fix this problem, update build.sbt to include the settings " +
413- " `mainClass.in( Compile) := Some(\" com.MainClass\" )`"
418+ " `Compile / mainClass := Some(\" com.MainClass\" )`"
414419 )
415420 )
416421 command += binaryName.absolutePath
417422
418423 // Start native-image linker.
419424 streams.value.log.info(command.mkString(" " ))
420- val cwd = target.in (NativeImage ).value
425+ val cwd = (NativeImage / target ).value
421426 cwd.mkdirs()
422427 val exit = Process (command, cwd = Some (cwd)).!
423428 if (exit != 0 ) {
@@ -431,17 +436,17 @@ object NativeImagePlugin extends AutoPlugin {
431436 binaryName
432437 },
433438 nativeImageTest := {
434- val _ = compile.in (Test ).value
435- val main = mainClass.in (NativeImageTest ).value
439+ val _ = (Test / compile ).value
440+ val main = (NativeImageTest / mainClass ).value
436441 val binaryName = nativeImageTestOutput.value
437- val cp = fullClasspath.in (Test ).value.map(_.data)
442+ val cp = (Test / fullClasspath ).value.map(_.data)
438443 // NOTE(olafur): we pass in a manifest jar instead of the full classpath
439444 // for two reasons:
440445 // * large classpaths quickly hit on the "argument list too large"
441446 // error, especially on Windows.
442447 // * we print the full command to the console and the manifest jar makes
443448 // it more readable and easier to copy-paste.
444- val manifest = target.in (NativeImageTestInternal ).value / " manifest.jar"
449+ val manifest = (NativeImageTestInternal / target ).value / " manifest.jar"
445450 manifest.getParentFile().mkdirs()
446451 createManifestJar(manifest, cp)
447452 val nativeClasspath = manifest.absolutePath
@@ -457,14 +462,14 @@ object NativeImagePlugin extends AutoPlugin {
457462 throw new MessageOnlyException (
458463 " no mainClass is specified for tests. " +
459464 " To fix this problem, update build.sbt to include the settings " +
460- " `mainClass.in( Test) := Some(\" com.MainTestClass\" )`"
465+ " `Test / mainClass := Some(\" com.MainTestClass\" )`"
461466 )
462467 )
463468 command += binaryName.absolutePath
464469
465470 // Start native-image linker.
466471 streams.value.log.info(command.mkString(" " ))
467- val cwd = target.in (NativeImageTest ).value
472+ val cwd = (NativeImageTest / target ).value
468473 cwd.mkdirs()
469474 val exit = Process (command, cwd = Some (cwd)).!
470475 if (exit != 0 ) {
@@ -519,8 +524,7 @@ object NativeImagePlugin extends AutoPlugin {
519524 // this happens if the dependency jar resides on a different drive then the manifest, i.e. C:\Coursier\Cache and D:\myapp\target
520525 // copy dependency next to manifest as fallback
521526 case _ : IllegalArgumentException =>
522- import java .nio .file .Files
523- import java .nio .file .StandardCopyOption
527+ import java .nio .file .{Files , StandardCopyOption }
524528 Files .copy(
525529 dependencyPath,
526530 manifestPath.resolve(path.getName),
@@ -546,15 +550,15 @@ object NativeImagePlugin extends AutoPlugin {
546550
547551 private def alertUser (streams : std.TaskStreams [_], message : String ): Unit = {
548552 streams.log.info(message)
549- if (isCI)
550- return
551- try {
552- if (Properties .isMac) {
553- Process (List (" say" , message)).!
553+ if (! isCI) {
554+ try {
555+ if (Properties .isMac) {
556+ Process (List (" say" , message)).!
557+ }
558+ // NOTE(olafur): feel free to add support for Linux/Windows.
559+ } catch {
560+ case NonFatal (_) =>
554561 }
555- // NOTE(olafur): feel free to add support for Linux/Windows.
556- } catch {
557- case NonFatal (_) =>
558562 }
559563 }
560564}
0 commit comments