truthy 不适用于 sbt new

truthy doesn't work with sbt new

我用giter8创建了一个模板项目,并尝试添加条件表达式。

defaults.properties我补充说:

param=true

并在我添加的模板文件中:

  $if(param.truthy)$
  ....
  $endif$

当我生成项目时:

g8 file://proj.g8

一切如预期。
在交互部分,param 将有 2 个选项:

param [YES/no]:

并且生成的文件将包含基于 param

值的附加文本

但是,当我生成项目时:

sbt new file://proj.g8

param 被视为字符串。
在交互部分,没有 yes/no 选项:

param [yes]:

我收到以下错误:

Exiting due to error in the template File: /tmp/giter8-135496483100759/src/main/g8/build.sbt, context [anonymous] 44:6 internal error: org.stringtemplate.v4.compiler.STException: context [anonymous] 44:6 no such property or can't access: java.lang.String.truthy Caused by: org.stringtemplate.v4.misc.STNoSuchPropertyException: no such property: java.lang.String.truthy at org.stringtemplate.v4.misc.ObjectModelAdaptor.throwNoSuchProperty(ObjectModelAdaptor.java:167) at org.stringtemplate.v4.misc.ObjectModelAdaptor.getProperty(ObjectModelAdaptor.java:89) at org.stringtemplate.v4.Interpreter.getObjectProperty(Interpreter.java:1200) at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:210) at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145) at org.stringtemplate.v4.ST.write(ST.java:427) at org.stringtemplate.v4.ST.render(ST.java:497) at org.clapper.scalasti.ST.render(ST.scala:285) at giter8.G8$.applyTemplate(g8.scala:102) at giter8.G8$.write(g8.scala:154) at giter8.G8$.write(g8.scala:138) at giter8.G8$.$anonfun$writeTemplates(g8.scala:396) at scala.util.control.Exception$Catch.$anonfun$opt(Exception.scala:242) at scala.util.control.Exception$Catch.apply(Exception.scala:224) at scala.util.control.Exception$Catch.opt(Exception.scala:242) at giter8.G8$.$anonfun$writeTemplates(g8.scala:396) at scala.collection.immutable.Stream.foreach(Stream.scala:530) at giter8.G8$.writeTemplates(g8.scala:386) at giter8.G8$.$anonfun$applyT(g8.scala:257) at scala.util.Either$RightProjection.flatMap(Either.scala:702) at giter8.G8$.applyT(g8.scala:249) at giter8.G8$.fromDirectory(g8.scala:62) at giter8.JgitHelper$.$anonfun$run(JgitHelper.scala:64) at scala.util.Either$RightProjection.flatMap(Either.scala:702) at giter8.JgitHelper$.run(JgitHelper.scala:63) at giter8.Giter8.$anonfun$run(giter8.scala:34) at scala.Option.map(Option.scala:146) at giter8.Giter8.run(giter8.scala:33) at sbtgiter8resolver.Giter8TemplateResolver.run(Giter8TemplateResolver.scala:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sbt.TemplateCommandUtil$.call(TemplateCommand.scala:100) at sbt.TemplateCommandUtil$.runTemplate(TemplateCommand.scala:78) at sbt.TemplateCommandUtil$.$anonfun$run(TemplateCommand.scala:58) at sbt.TemplateCommandUtil$.$anonfun$run$adapted(TemplateCommand.scala:54) at scala.collection.LinearSeqOptimized.find(LinearSeqOptimized.scala:111) at scala.collection.LinearSeqOptimized.find$(LinearSeqOptimized.scala:108) at scala.collection.immutable.List.find(List.scala:86) at sbt.TemplateCommandUtil$.run(TemplateCommand.scala:54) at sbt.TemplateCommandUtil$.runTemplate(TemplateCommand.scala:41) at sbt.TemplateCommandUtil$.$anonfun$templateCommand(TemplateCommand.scala:24) at sbt.Command$.$anonfun$applyEffect(Command.scala:134) at sbt.Command$.$anonfun$applyEffect(Command.scala:130) at sbt.MainLoop$.processCommand(MainLoop.scala:153) at sbt.MainLoop$.$anonfun$next(MainLoop.scala:136) at sbt.State$$anon.runCmd(State.scala:242) at sbt.State$$anon.process(State.scala:248) at sbt.MainLoop$.$anonfun$next(MainLoop.scala:136) at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16) at sbt.MainLoop$.next(MainLoop.scala:136) at sbt.MainLoop$.run(MainLoop.scala:129) at sbt.MainLoop$.$anonfun$runWithNewLog(MainLoop.scala:107) at sbt.io.Using.apply(Using.scala:22) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:101) at sbt.MainLoop$.runAndClearLast(MainLoop.scala:57) at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:42) at sbt.MainLoop$.runLogged(MainLoop.scala:34) at sbt.StandardMain$.runManaged(Main.scala:113) at sbt.xMain.run(Main.scala:76) at xsbt.boot.Launch$$anonfun$run.apply(Launch.scala:109) at xsbt.boot.Launch$.withContextLoader(Launch.scala:128) at xsbt.boot.Launch$.run(Launch.scala:109) at xsbt.boot.Launch$$anonfun$apply.apply(Launch.scala:35) at xsbt.boot.Launch$.launch(Launch.scala:117) at xsbt.boot.Launch$.apply(Launch.scala:18) at xsbt.boot.Boot$.runImpl(Boot.scala:41) at xsbt.boot.Boot$.main(Boot.scala:17) at xsbt.boot.Boot.main(Boot.scala)

at giter8.G8$STErrorHandler.runTimeError(g8.scala:110) at giter8.G8$STErrorHandler.runTimeError(g8.scala:105) at org.stringtemplate.v4.misc.ErrorManager.runTimeError(ErrorManager.java:137) at org.stringtemplate.v4.Interpreter.getObjectProperty(Interpreter.java:1203) at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:210) at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145) at org.stringtemplate.v4.ST.write(ST.java:427) at org.stringtemplate.v4.ST.render(ST.java:497) at org.clapper.scalasti.ST.render(ST.scala:285) at giter8.G8$.applyTemplate(g8.scala:102) at giter8.G8$.write(g8.scala:154) at giter8.G8$.write(g8.scala:138) at giter8.G8$.$anonfun$writeTemplates(g8.scala:396) at scala.util.control.Exception$Catch.$anonfun$opt(Exception.scala:242) at scala.util.control.Exception$Catch.apply(Exception.scala:224) at scala.util.control.Exception$Catch.opt(Exception.scala:242) at giter8.G8$.$anonfun$writeTemplates(g8.scala:396) at scala.collection.immutable.Stream.foreach(Stream.scala:530) at giter8.G8$.writeTemplates(g8.scala:386) at giter8.G8$.$anonfun$applyT(g8.scala:257) at scala.util.Either$RightProjection.flatMap(Either.scala:702) at giter8.G8$.applyT(g8.scala:249) at giter8.G8$.fromDirectory(g8.scala:62) at giter8.JgitHelper$.$anonfun$run(JgitHelper.scala:64) at scala.util.Either$RightProjection.flatMap(Either.scala:702) at giter8.JgitHelper$.run(JgitHelper.scala:63) at giter8.Giter8.$anonfun$run(giter8.scala:34) at scala.Option.map(Option.scala:146) at giter8.Giter8.run(giter8.scala:33) at sbtgiter8resolver.Giter8TemplateResolver.run(Giter8TemplateResolver.scala:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sbt.TemplateCommandUtil$.call(TemplateCommand.scala:100) at sbt.TemplateCommandUtil$.runTemplate(TemplateCommand.scala:78) at sbt.TemplateCommandUtil$.$anonfun$run(TemplateCommand.scala:58) at sbt.TemplateCommandUtil$.$anonfun$run$adapted(TemplateCommand.scala:54) at scala.collection.LinearSeqOptimized.find(LinearSeqOptimized.scala:111) at scala.collection.LinearSeqOptimized.find$(LinearSeqOptimized.scala:108) at scala.collection.immutable.List.find(List.scala:86) at sbt.TemplateCommandUtil$.run(TemplateCommand.scala:54) at sbt.TemplateCommandUtil$.runTemplate(TemplateCommand.scala:41) at sbt.TemplateCommandUtil$.$anonfun$templateCommand(TemplateCommand.scala:24) at sbt.Command$.$anonfun$applyEffect(Command.scala:134) at sbt.Command$.$anonfun$applyEffect(Command.scala:130) at sbt.MainLoop$.processCommand(MainLoop.scala:153) at sbt.MainLoop$.$anonfun$next(MainLoop.scala:136) at sbt.State$$anon.runCmd(State.scala:242) at sbt.State$$anon.process(State.scala:248) at sbt.MainLoop$.$anonfun$next(MainLoop.scala:136) at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16) at sbt.MainLoop$.next(MainLoop.scala:136) at sbt.MainLoop$.run(MainLoop.scala:129) at sbt.MainLoop$.$anonfun$runWithNewLog(MainLoop.scala:107) at sbt.io.Using.apply(Using.scala:22) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:101) at sbt.MainLoop$.runAndClearLast(MainLoop.scala:57) at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:42) at sbt.MainLoop$.runLogged(MainLoop.scala:34) at sbt.StandardMain$.runManaged(Main.scala:113) at sbt.xMain.run(Main.scala:76) at xsbt.boot.Launch$$anonfun$run.apply(Launch.scala:109) at xsbt.boot.Launch$.withContextLoader(Launch.scala:128) at xsbt.boot.Launch$.run(Launch.scala:109) at xsbt.boot.Launch$$anonfun$apply.apply(Launch.scala:35) at xsbt.boot.Launch$.launch(Launch.scala:117) at xsbt.boot.Launch$.apply(Launch.scala:18) at xsbt.boot.Boot$.runImpl(Boot.scala:41) at xsbt.boot.Boot$.main(Boot.scala:17) at xsbt.boot.Boot.main(Boot.scala)

我正在为 g8sbt-giter8 插件使用版本 0.11.0-M3

我该如何解决这个问题?

编辑:更多细节:
我正在使用 sbt 1.1.1(用于我机器上的 g8 项目和 sbt 启动器)
我在文件 project/plugins.sbt

的 g8 项目中添加了插件
addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.11.0-M3")

如果我从模板中删除真实的部分,项目就会从 sbt new

中正确生成

此问题已在 sbt 1.2.0 中修复
为了修复,应该使用:
sbt -Dsbt.version=1.2.0 new file://proj.g8

sbt new 内部使用的 giter8 版本是固定的,添加 sbt-giter8 插件不会改变它。 sbt 1.1.1 uses sbt-giter8-resolver v0.1.3, which uses giter8 0.7.2(不支持条件)。

你可以更新 sbt-giter8-resolver,在本地发布并尝试替换默认的 Giter8TemplatePlugin,但我认为这不值得。直接使用 g8 直到 sbt 更新。

was an effort to support arbitrary giter8 version set in the template, but something went wrong,此功能已恢复。