sbtgiter8

truthy doesn't work with sbt new


I've created a template project with giter8, and trying to add conditional expression.

in the defaults.properties I added:

param=true

and in the template file I added:

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

when I'm generating the project with:

g8 file://proj.g8

everything works as expected.
in the interactive part, param would have 2 options:

param [YES/no]:

and the generated file will include the additional text based on the value of the param

But, when I generate the project with:

sbt new file://proj.g8

param is being treated as a string.
during the interactive part, there are no yes/no options:

param [yes]:

and I'm getting the following error:

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$3(g8.scala:396) at 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) 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$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) 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$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$.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 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) 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$1.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$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) 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$3(g8.scala:396) at 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) 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$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) 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$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$.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 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) 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$1.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$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) at xsbt.boot.Boot.main(Boot.scala)

I'm using version 0.11.0-M3 for both g8 and sbt-giter8 plugin

How can I fix this problem?

EDIT: some more details:
I'm using sbt 1.1.1 (for both the g8 project and the sbt launcher on my machine)
I added the plugin in the g8 project in the file project/plugins.sbt with

addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.11.0-M3")

if I remove the truthy parts from the template, the project is generated correctly from sbt new


This issue been fixed in sbt 1.2.0
in order to fix, should use:
sbt -Dsbt.version=1.2.0 new file://proj.g8


Solution

  • The version of giter8 used internally for sbt new is fixed and adding sbt-giter8 plugin won't change it. sbt 1.1.1 uses sbt-giter8-resolver v0.1.3, which uses giter8 0.7.2 (which doesn't support conditionals).

    You could update sbt-giter8-resolver, publish it locally and try to replace the default Giter8TemplatePlugin, but I think it's not worth it. Just use g8 directly until sbt gets updated.

    There was an effort to support arbitrary giter8 version set in the template, but something went wrong and this feature has been reverted.