truthy不能与sbt new

时间:2018-03-24 03:46:23

标签: sbt giter8

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

我添加的defaults.properties中的

param=true

在我添加的模板文件中:

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

当我用:

生成项目时
g8 file://proj.g8

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

  

param [是/否]

,生成的文件将包含基于param

值的附加文本

但是,当我用:

生成项目时
sbt new file://proj.g8

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

  

param [是]

我收到以下错误:

  

由于模板文件中的错误而退出:   /tmp/giter8-135496483100759/src/main/g8/build.sbt,context [anonymous]   44:6内部错误:org.stringtemplate.v4.compiler.STException:   context [anonymous] 44:6没有这样的财产或无法访问:   java.lang.String.truthy引起:   org.stringtemplate.v4.misc.STNoSuchPropertyException:没有这样的   property:java.lang.String.truthy at   org.stringtemplate.v4.misc.ObjectModelAdaptor.throwNoSuchProperty(ObjectModelAdaptor.java:167)     在   org.stringtemplate.v4.misc.ObjectModelAdaptor.getProperty(ObjectModelAdaptor.java:89)     在   org.stringtemplate.v4.Interpreter.getObjectProperty(Interpreter.java:1200)     在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 at   giter8.G8 $。$ anonfun $ writeTemplates $ 3(g8.scala:396)at at   。scala.util.control.Exception $抓$ anonfun $选择$ 1(Exception.scala:242)     在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 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.E $ 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 at   scala.util.E $ 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)at   sbtgiter8resolver.Giter8TemplateResolver.run(Giter8TemplateResolver.scala:31)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在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 $ 1(TemplateCommand.scala:58)at at   sbt.TemplateCommandUtil $ $ $ anonfun运行$ 1 $适应(TemplateCommand.scala:54)。     在   scala.collection.LinearSeqOptimized.find(LinearSeqOptimized.scala:111)     在   scala.collection.LinearSeqOptimized.find $(LinearSeqOptimized.scala:108)     在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 2(TemplateCommand.scala:24)     at 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 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 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 at   sbt.io.Using.apply(Using.scala:22)at   sbt.MainLoop $ .runWithNewLog(MainLoop.scala:101)at at   sbt.MainLoop $ .runAndClearLast(MainLoop.scala:57)at at   sbt.MainLoop $ .runLoggedLoop(MainLoop.scala:42)at 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 $ 1.apply(Launch.scala:109)at at   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 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 at   giter8.G8 $ STErrorHandler.runTimeError(g8.scala:105)at   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)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 at   giter8.G8 $。$ anonfun $ writeTemplates $ 3(g8.scala:396)at at   。scala.util.control.Exception $抓$ anonfun $选择$ 1(Exception.scala:242)     在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 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.E $ 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 at   scala.util.E $ 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)at   sbtgiter8resolver.Giter8TemplateResolver.run(Giter8TemplateResolver.scala:31)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在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 $ 1(TemplateCommand.scala:58)at at   sbt.TemplateCommandUtil $ $ $ anonfun运行$ 1 $适应(TemplateCommand.scala:54)。     在   scala.collection.LinearSeqOptimized.find(LinearSeqOptimized.scala:111)     在   scala.collection.LinearSeqOptimized.find $(LinearSeqOptimized.scala:108)     在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 2(TemplateCommand.scala:24)     at 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 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 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 at   sbt.io.Using.apply(Using.scala:22)at   sbt.MainLoop $ .runWithNewLog(MainLoop.scala:101)at at   sbt.MainLoop $ .runAndClearLast(MainLoop.scala:57)at at   sbt.MainLoop $ .runLoggedLoop(MainLoop.scala:42)at 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 $ 1.apply(Launch.scala:109)at at   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 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)

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

如何解决此问题?

编辑:更多细节:
我使用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

1 个答案:

答案 0 :(得分:3)

sbt new内部使用的giter8版本已修复,添加sbt-giter8插件无法更改。 sbt 1.1.1 uses sbt-giter8-resolver v0.1.3,uses giter8 0.7.2(不支持条件)。

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

was an effort来支持任意giter8版本set in the template,但went wrong并且此功能已被恢复。