在 picocli 中,他们给出了如何在构建 Maven 和 Gradle 期间生成 GraalVM 反射配置的示例。
摇篮示例
configurations {
generateConfig
}
dependencies {
compile 'info.picocli:picocli:3.9.3'
generateConfig 'info.picocli:picocli-codegen:3.9.3'
}
任务
task(generateGraalReflectionConfig, dependsOn: 'classes', type: JavaExec) {
main = 'picocli.codegen.aot.graalvm.ReflectionConfigGenerator'
classpath = configurations.generateConfig + sourceSets.main.runtimeClasspath
def outputFile = new File(project.buildDir, 'cli-reflect.json')
args = ["--output=$outputFile", 'com.your.package.YourCommand1', 'com.your.package.YourCommand2']
}
assemble.dependsOn generateGraalReflectionConfig
我怎么能为 sbt 写一些等效的东西?
这是我到目前为止所得到的,但我不知道我是否朝着正确的方向前进。
import Dependencies._
ThisBuild / scalaVersion := "2.12.8"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "com.example"
ThisBuild / organizationName := "example"
lazy val root = (project in file("."))
.settings(
name := "poc-cli",
libraryDependencies += scalaTest % Test,
libraryDependencies += "info.picocli" % "picocli" % "3.9.3",
libraryDependencies += "info.picocli" % "picocli-codegen" % "3.9.3",
)
lazy val graalConfig = inputKey[Unit]("gen-graal-config")
graalConfig:= {
val conf = (runMain in Compile).fullInput(" picocli.codegen.aot.graalvm.ReflectionConfigGenerator --output=cli-reflect.json example.Hello").evaluated
}
enablePlugins(GraalVMNativeImagePlugin)
编辑
在我最初的问题中,我有下面的代码,用我当前的代码问题解决了
lazy val graalConfig = taskKey[Unit]("graal-config") := {
Process("java" :: "-jar" :: "picocli.codegen.aot.graalvm.ReflectionConfigGenerator" :: "--output" :: "cli-reflect.json" :: "???" :: Nil,
baseDirectory.value / "lib").!
}