sbt - How to copy files to target so they are used in run task? -
i re-create artifact repository target
subdirectory, before invoke special run
task.
// audit task must invoke run task, after re-create artifact in directory audit := { println("in audit") // 1. re-create artifact directory val auditagent = ((fullclasspath in test value) filter (_.data.getname.startswith("reactive-audit-agent"))).head.data val targetagent= target.value / "reactive-audit-libs" / "reactive-audit-agent.jar" io.copyfile(auditagent,targetagent) // 2. set javaopt. javaoptions += "-javagent:"+targetagent // 3. invoke run task javaagent ??? }
with sbt run
run project. sbt audit
run project specific javagent.
i seek utilize fullruntask(audit,...)
extend audit
task, body in audit
not running
audit := { println("in audit") } fullruntask(audit, runtime, "com.octo.reactive.sample.testapp")
custom configuration update report
based upon configurations , update report i've figured out approach declare dependency , utilize in task. approach explicitly declares dependency on external file that's required task, become java agent.
what seem have missed in past revisions of reply requirement:
with sbt run
run project. sbt audit
run project specific javagent.
the next build.sbt
gives solution (it assumes sbt 0.13.7-m3 the alter no blank lines - add together blank lines if don't want upgrade yet):
lazy val agent = config("agent") extend runtime inconfig(agent)(defaults.configsettings) sourcedirectory in agent <<= sourcedirectory in compile ivyconfigurations += agent // makes file available in ivy2 local repository librarydependencies += "org.aspectj" % "aspectjweaver" % "1.8.2" % "agent" fork in (agent, run) := true javaoptions in (agent, run) += "-javaagent:" + update.value.select(configurationfilter("agent")).filter(_.name.contains("aspectjweaver")).head addcommandalias("audit", "agent:run")
the build defines new hidden agent
configuration dependency belongs configuration only.
using update
(as described in update report) select declared dependency "agent" run
, since configuration extend runtime
had exclude other "transitive" dependencies (that runtime
gives).
when execute run
runs old run
task - no changes here:
> run [info] running com.example.hello hello, world!
when run agent:run
executes custom run
in agent
configuration (you see no alter unless alter - create typo in - -javaagent
else breaks startup):
> agent:run [info] running com.example.hello [info] hello, world!
as final solution there's audit
alias that's agent:run
.
> audit [info] running com.example.hello [info] hello, world!
with solution sbt downloads dependency usual (so don't have worry if file exists or not , when not, build fail).
copying files directory using resource generatorshow can re-create files directory, before run project ?
read page generating files find section generate resources says:
a resource generation task should generate resources in subdirectory of resourcemanaged , homecoming sequence of files generated.
do show resourcemanaged
find out path that's default under target/scala-[scalaversion]
.
sbt
No comments:
Post a Comment