如何将ScalaFXML与Gradle相结合? [英] How does one combine ScalaFXML with Gradle?

查看:156
本文介绍了如何将ScalaFXML与Gradle相结合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我先设定最终目标: 我想构建仅Scala的gui应用程序,可以使用场景构建器和更高版本进行设计将 gluon 移植到我想要的任何平台.

Let me set up my end goal first: I want to build a scala only gui application, that I can design with scene builder and later port with gluon to any platform I want to.

我发现,需要在Scala中使用 JavaFXPorts 来做到这一点.我还发现我需要使用gradle成功地应用胶子,或者看起来(如果我做错了,请纠正我,因为那是头痛的开始)

I was able to find out, that one needs to use JavaFXPorts in Scala to make that happen. I also found out that I need to use gradle to apply gluon successfully, or so it seems (please correct me if I am wrong because that's where the headache starts)

简而言之,这意味着:ScalaFXML和Gradle需要一起工作,但是如何合作?

我找到了一些有趣的项目,但不幸的是,这些项目都没有符合我的标准:

I've found some interesting projects, but sadly none of these hit my criteria just right:

  • 使用JavaFX代替ScalaFX
  • 一个将Java添加到了项目中,而不是使用纯Java.斯卡拉
  • This one used JavaFX instead of ScalaFX
  • This one added Java to the project instead of using pure scala

经过长时间的搜索,我发现了一个项目 ,那几乎是正确的.可悲的是,这是在sbt中构建的,而不是在gradle中构建的. 尽管如此,我还是以该项目作为基础/示例,因为这是第一个在 sfxml 中使用的项目.容易理解的方式.

After a long time searching I found a project, that was almost right. Sadly, this was built in sbt and not in gradle. None the less I used that project as a base/example, as this was the first to use sfxml in way that was easily understood.

我有一个gradle脚本,几乎可以正常工作

I have a gradle script, that almost works

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导入过程中没有标记任何错误,但是最后我得到了以下错误:

After finally finding all the right repositories (or so I thought) no errors were marked down during the import process from IDEA, but at last I got the following error:

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脚本-我已经尝试启用该插件.那么,如何解决这个问题并实现开始时所述的目标?

But as you might have figured out - if you've read the gradle script - I already tried enabling the plugin. So how do I fix this and achieve the goal stated at the beginning?

顺便说一句:我已经找到了以下解决方案,但是这些解决方案也没有用

Btw: I already found the following solutions, but those also didn't work

  • 使用了maven,但是我想用gradle,还是... Google吗?
  • 可悲的是不行
  • 可悲的是...也不起作用:/
  • This uses maven, but I want to use gradle, soo... thx google?
  • This sadly doesn't work
  • This sadly... also does not work :/

脚注:所有SDK均在发布时立即下载

Footnote: All SDKs are freshly downloaded at the time of this posting

推荐答案

因此,在重新访问gradle脚本并检查了前面提到的工作范围后,我发现了自己的错误.

So after revisiting my gradle script and checking against the previously mentioned work arrounds, I found my mistake.

我没有提供此处.因此,在将build.gradle编辑为仅包含必要的内容之后,我得到了以下信息:

I didn't include the complete answer from here. So after editing my build.gradle to only include the necessary things, I got the following:

plugins {
    id 'java'
    id 'scala'
}
apply plugin: 'org.javafxports.jfxmobile'

configurations {
    scalaCompiler
}
configurations.scalaCompiler.transitive = false


compileScala.targetCompatibility = "1.8"

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    compile 'org.scala-lang:scala-library:2.12.6'

    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'

    scalaCompiler "org.scalamacros:paradise_2.12.6:2.1.1"

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

def String scalaCompilerOptions="-Xplugin:$configurations.scalaCompiler.singleFile.path"
compileScala.scalaCompileOptions.additionalParameters = [scalaCompilerOptions]
compileTestScala.scalaCompileOptions.additionalParameters = [scalaCompilerOptions]

该脚本将运行此使用gradle而不是sbt进行项目.

旁注: 如果出现错误无法加载资源:AdoptionForm.fxml",请阅读以下发布

Side note: If you get the error "Cannot load resource: AdoptionForm.fxml" read the following post

由于我现在还没有使用胶子,所以我还没有完成之前所说的目标.但是这篇文章的主要问题已经解决,所以我将其标记为正确的答案.

I didn't complete my previously stated goal just yet, since I haven't used gluon for now. But the main problem of this post is solved, so I will mark this as the right answer.

如果以后可以工作,我可能会添加胶子集成.

I might add the gluon integration later if I get it to work.

这篇关于如何将ScalaFXML与Gradle相结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆