2

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

defaults.properties我补充说:

param=true

在我添加的模板文件中:

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

当我生成项目时:

g8 file://proj.g8

一切都按预期工作。
在交互部分,param将有 2 个选项:

参数[是/否]

并且生成的文件将包含基于值的附加文本param

但是,当我生成项目时:

sbt new file://proj.g8

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

参数[是]

我收到以下错误:

由于模板文件中的错误而退出:/tmp/giter8-135496483100759/src/main/g8/build.sbt, context [anonymous] 44:6 internal error: org.stringtemplate.v4.compiler.STException: context [anonymous] 44:6 没有这样的属性或无法访问:java.lang.String.truthy 原因:org.stringtemplate.v4.misc.STNoSuchPropertyException:没有这样的属性:org.stringtemplate.v4 的 java.lang.String.truthy。 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) 在 org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145) 在 org.stringtemplate.v4.ST.write(ST.java:427) 在 org.clapper.scalasti.ST.render(ST.scala:285) 在 org.stringtemplate.v4.ST.render(ST.java:497) 在 giter8.G8$.applyTemplate(g8.scala:102)在 giter8.G8$.write(g8.scala:154) 在 giter8.G8$.write(g8.scala:138) 在 giter8.G8$.$anonfun$writeTemplates$3(g8.scala:396) 在 scala.util .control.Exception$Catch.$anonfun$opt$1(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$2(g8.scala:396) at scala.collection.immutable.Stream.foreach(Stream.scala:530) at giter8.G8$.writeTemplates( g8.scala:386) at giter8.G8$.$anonfun$applyT$1(g8.scala:257) at scala.util.Either$RightProjection.flatMap(Either.scala:702) at giter8.G8$.applyT(g8 .scala:249) 在 giter8.G8$。fromDirectory(g8.scala:62) at giter8.JgitHelper$.$anonfun$run$3(JgitHelper.scala:64) at scala.util.Either$RightProjection.flatMap(Either.scala:702) at giter8.JgitHelper$.run (JgitHelper.scala:63) at giter8.Giter8.$anonfun$run$2(giter8.scala:34) at scala.Option.map(Option.scala:146) at giter8.Giter8.run(giter8.scala:33)在 sbtgiter8resolver.Giter8TemplateResolver.run(Giter8TemplateResolver.scala:31) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 sbt.TemplateCommandUtil$.call(TemplateCommand.scala:100) 在 sbt.TemplateCommandUtil$。runTemplate(TemplateCommand.scala:78) at sbt.TemplateCommandUtil$.$anonfun$run$1(TemplateCommand.scala:58) at sbt.TemplateCommandUtil$.$anonfun$run$1$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$。在 sbt.TemplateCommandUtil$.runTemplate(TemplateCommand.scala:41) 在 sbt.TemplateCommandUtil$.$anonfun$templateCommand$2(TemplateCommand.scala:24) 在 sbt.Command$.$anonfun$applyEffect 运行(TemplateCommand.scala:54) $4(Command.scala:134) at sbt.Command$.$anonfun$applyEffect$2(Command.scala:130) at sbt.MainLoop$.processCommand(MainLoop.scala:153) at sbt.MainLoop$.$anonfun$next 2 美元(主循环。scala:136) at sbt.State$$anon$1.runCmd$1(State.scala:242) at sbt.State$$anon$1.process(State.scala:248) at sbt.MainLoop$.$anonfun$next$1 (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$1(MainLoop.scala:107) at sbt.io.Using.apply(Using.scala:22) at sbt.MainLoop$.runWithNewLog(MainLoop.scala:101)在 sbt.MainLoop$.runAndClearLast(MainLoop.scala:57) 在 sbt.MainLoop$.runLoggedLoop(MainLoop.scala:42) 在 sbt.MainLoop$.runLogged(MainLoop.scala:34) 在 sbt.StandardMain$.runManaged( Main.scala:113) 在 sbt.xMain.run(Main.scala:76) 在 xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109) 在 xsbt.boot.Launch$。withContextLoader(Launch.scala:128) at xsbt.boot.Launch$.run(Launch.scala:109) at xsbt.boot.Launch$$anonfun$apply$1.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) 在 xsbt.boot.Boot.main(Boot.scala)

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

我同时使用0.11.0-M3版本g8sbt-giter8插件

我该如何解决这个问题?

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

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

4

1 回答 1

3

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

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

曾努力支持模板中设置的任意giter8版本,但出现问题,此功能已恢复。

于 2018-03-24T04:24:26.707 回答