【发布时间】:2018-12-08 01:21:13
【问题描述】:
让我先设定我的最终目标: 我想构建一个仅 scala 的 gui 应用程序,我可以使用 scene builder 进行设计,然后将 gluon 移植到我想要的任何平台。
我发现,需要在 Scala 中使用 JavaFXPorts 才能实现这一目标。我还发现我需要使用 gradle 才能成功应用胶子,或者看起来是这样(如果我错了,请纠正我,因为这就是头痛的开始)
简而言之,这意味着:ScalaFXML 和 Gradle 需要协同工作,但如何?
我发现了一些有趣的项目,但遗憾的是,这些项目都没有达到我的标准:
经过长时间的搜索,我找到了project,这几乎是正确的。可悲的是,这是在 sbt 中构建的,而不是在 gradle 中构建的。 尽管如此,我还是将该项目用作基础/示例,因为这是第一个以易于理解的方式使用sfxml。
我有一个 gradle 脚本,几乎可以工作
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
// during build, we depend on the jfxmobile-plugin
classpath 'org.javafxports:jfxmobile-plugin:1.3.10'
}
}
plugins {
id 'java'
id 'scala'
id 'application'
}
apply plugin: 'org.javafxports.jfxmobile'
configurations {
scalaCompiler
scalaCompilerPlugin
}
configurations.scalaCompiler.transitive = false
compileScala.targetCompatibility = "1.8"
mainClassName = 'sfxml.Main'
repositories {
mavenCentral()
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
compile 'org.scala-lang:scala-library:2.12.6'
compile 'org.scala-lang:scala-compiler:2.12.6'
compile 'com.gluonhq:particle:1.1.3'
compile group: 'org.scalafx', name: 'scalafx_2.12', version: '8.0.144-R12'
compile group: 'org.scalafx', name: 'scalafxml-core-sfx8_2.12', version: '0.4'
compile group: 'org.scalamacros', name: 'paradise_2.12.6', version: '2.1.1'
scalaCompiler "org.scalamacros:paradise_2.12.6:2.1.1"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
tasks.withType(ScalaCompile) {
scalaCompileOptions.additionalParameters = [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-Ymacro-debug-lite"
]
options.compilerArgs = ["-Xdebug", "-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=9999"]
}
在最终找到所有正确的存储库(或者我认为)之后,在从 IDEA 导入过程中没有标记任何错误,但最后我收到以下错误:
Error:(10, 7) macro annotation could not be expanded (the most common reason for that is that you need to enable the macro paradise plugin; another possibility is that you try to use macro annotation in the same compilation run that defines it)
class AdoptionFormPresenter(private val sizeTextField: TextField,
但正如您可能已经知道的那样 - 如果您已经阅读了 gradle 脚本 - 我已经尝试过启用该插件。那么如何解决这个问题并实现开头所述的目标呢?
顺便说一句:我已经找到了以下解决方案,但那些也没有工作
脚注:所有 SDK 在本文发布时都是新下载的
【问题讨论】: