将Groovy应用程序和测试代码与jlink解决方案结合使用以捆绑JavaFX [英] Use Groovy app and test code in combination with jlink solution for bundling JavaFX

查看:214
本文介绍了将Groovy应用程序和测试代码与jlink解决方案结合使用以捆绑JavaFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接着是这个出色的解决方案,该问题解决了如何使Gradle将JavaFX与您的发行版捆绑在一起的问题.

This follows on from this excellent solution to the question of how to get Gradle to bundle up JavaFX with your distributions.

NB规格:Linux Mint 18.3,Java 11,JavaFX 13.

NB specs: Linux Mint 18.3, Java 11, JavaFX 13.

涉及jlink和module-info.java的东西超出了我的薪水等级(尽管我正在尝试阅读这些东西).

That stuff, involving jlink and a module-info.java, is beyond my pay grade (although I'm trying to read up on these things).

我想转向在我的应用程序和测试代码(例如Spock)中使用Groovy,而不是Java.问题是,在我将build.gradle中包含正常"依赖项的那一刻,即

I want to move to using Groovy in my app and test code (i.e. Spock) rather than Java. The trouble is, the minute I include the "normal" dependency in my build.gradle i.e.

implementation 'org.codehaus.groovy:groovy-all:2.5.9'

尝试构建,出现多个错误:

and try to build, I get multiple errors:

mike@M17A ~/IdeaProjects/TestProj $  ./gradlew build

> Configure project :
Found module name 'javafx.jlink.example.main'

> Task :compileTestJava FAILED
error: the unnamed module reads package org.codehaus.groovy.tools.shell.util from both org.codehaus.groovy.groovysh and org.codehaus.groovy
[...]
error: the unnamed module reads package groovy.xml from both org.codehaus.groovy and org.codehaus.groovy.xml
[...]
error: module org.codehaus.groovy.ant reads package groovy.lang from both org.codehaus.groovy and org.codehaus.groovy.test
error: module org.codehaus.groovy.ant reads package groovy.util from both org.codehaus.groovy.xml and org.codehaus.groovy.ant
100 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestJava'.

是的,有100个错误,可能还有更多!通过注释掉各种事情,我认为我得出的结论是jlink东西注入了一些Groovy依赖.很好,我可以接受(尽管很高兴知道它是Groovy的哪个版本).

Yes, 100 errors... probably more! By commenting out various things I think I've come to the conclusion that some Groovy dependency is being injected by the jlink stuff. Fine, I can live with that (although it'd be nice to know what version of Groovy it is).

问题在于,即使我省略了Groovy依赖项行,当我尝试引入Spock依赖项时也会发生相同的错误:

The trouble is, even if I omit the Groovy dependency line, the same errors occur when I try to introduce the Spock dependency:

testImplementation 'org.spockframework:spock-core:1.2-groovy-2.5'

有没有人知道这里发生了什么以及如何处理?

Has anyone got any idea what's going on here and what to do about it?

推荐答案

我搜索了答案.我没有找到一个好的解决方案.

I searched for an answer. I didn't find a good solution.

根据 this ,看来Groovy当前实际上与Java模块不兼容.这是由于某些包包含在库的多个jar中(与模块不兼容).您将不得不等待Groovy 4的兼容版本.

According to this, it seems that Groovy is currently not really compatible with Java modules. It is due to the fact that some packages are contained by multiple jars of the library (not compatible with modules). You will have to wait for Groovy 4 for a compatible version.

我发现JavaFX插件在内部使用此插件.该插件似乎认为所有依赖项都是模块(这不是默认的Gradle行为).

I discovered that the JavaFX plugin use this plugin internally. This plugin seems to consider that all dependencies are modules (it is not the default Gradle behaviour).

要使您的应用程序正常工作,您似乎必须:

To make your application works, it seems that you have to:

  • force Gradle将Groovy放在类路径而不是模块路径中(它不会被视为模块,但是如果使用javafx插件,似乎是不可能的)
  • 使用补丁模块"系统:它允许Gradle将库jar融合到单个模块中,以防止不同jar中的软件包出现问题.

我用IDEA(项目结构/库)搜索了Groovy罐子,然后尝试使用插件提供的语法来使用补丁模块":

I searched the Groovy jars with IDEA (Project structure/Libraries), and I tried to use the syntax offered by the plugin to use "patch-module":

patchModules.config = [
    "org.codehaus.groovy=groovy-ant-3.0.1.jar",
    "org.codehaus.groovy=groovy-cli-picocli-3.0.1.jar",
    "org.codehaus.groovy=groovy-console-3.0.1.jar",
    "org.codehaus.groovy=groovy-datetime-3.0.1.jar",
    "org.codehaus.groovy=groovy-docgenerator-3.0.1.jar",
    "org.codehaus.groovy=groovy-groovydoc-3.0.1.jar",
    "org.codehaus.groovy=groovy-groovysh-3.0.1.jar",
    "org.codehaus.groovy=groovy-jmx-3.0.1.jar",
    "org.codehaus.groovy=groovy-json-3.0.1.jar",
    "org.codehaus.groovy=groovy-jsr-3.0.1.jar",
    "org.codehaus.groovy=groovy-macro-3.0.1.jar",
    "org.codehaus.groovy=groovy-nio-3.0.1.jar",
    "org.codehaus.groovy=groovy-servlet-3.0.1.jar",
    "org.codehaus.groovy=groovy-sql-3.0.1.jar",
    "org.codehaus.groovy=groovy-swing-3.0.1.jar",
    "org.codehaus.groovy=groovy-templates-3.0.1.jar",
    "org.codehaus.groovy=groovy-test-junit-3.0.1.jar",
    "org.codehaus.groovy=groovy-test-3.0.1.jar",
    "org.codehaus.groovy=groovy-testng-3.0.1.jar",
    "org.codehaus.groovy=groovy-xml-3.0.1.jar"
]

它仅适用于单行"org.codehaus.groovy = X.jar",但是有一个错误阻止它与所有库jar一起使用(请查看

It only works with a single line "org.codehaus.groovy=X.jar", but a bug prevents it to work with all of the library jars (Look at this issue on Github).

因此,您有多种选择:

这篇关于将Groovy应用程序和测试代码与jlink解决方案结合使用以捆绑JavaFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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