制作一个使用Gradle构建的JavaFX跨平台版本。

huangapple go评论82阅读模式
英文:

Making a cross-platform build of JavaFX using Gradle

问题

我正在使用Gradle和JavaFX开展一个新项目。之前我曾使用Maven创建跨平台构建,其pom依赖如下:

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics</artifactId>
    <version>13</version>
    <classifier>win</classifier>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics</artifactId>
    <version>13</version>
    <classifier>linux</classifier>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-graphics</artifactId>
    <version>13</version>
    <classifier>mac</classifier>
</dependency>

在Gradle中如何执行类似的操作呢?我尝试了以下方式,但没有成功。分类器的语法有误吗?

compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2:win'
compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2:linux'
compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2:mac'

非常感谢任何提示!

英文:

I'm working on a new project using Gradle and JavaFX.
I have previously been able to create a cross-platform build using Maven, with the following pom dependencies:

&lt;dependency&gt;
            &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
            &lt;artifactId&gt;javafx-graphics&lt;/artifactId&gt;
            &lt;version&gt;13&lt;/version&gt;
            &lt;classifier&gt;win&lt;/classifier&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
            &lt;artifactId&gt;javafx-graphics&lt;/artifactId&gt;
            &lt;version&gt;13&lt;/version&gt;
            &lt;classifier&gt;linux&lt;/classifier&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.openjfx&lt;/groupId&gt;
            &lt;artifactId&gt;javafx-graphics&lt;/artifactId&gt;
            &lt;version&gt;13&lt;/version&gt;
            &lt;classifier&gt;mac&lt;/classifier&gt;
        &lt;/dependency&gt;

How do i go about doing something similar with Gradle?
I have tried the following, with no success.
Is the classifier syntax incorrect?

compile group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: &#39;11.0.2:win&#39;
compile group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: &#39;11.0.2:linux&#39;
compile group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: &#39;11.0.2:mac&#39;

Any hints would be greatly appreciated!

答案1

得分: 2

解决方案是以下 Gradle 构建依赖项:

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'

这使得可以在任何操作系统上运行 JavaFX Gradle 构建。

英文:

The solution turned out to be the following gradle build dependencies:

implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-base&#39;, version: javaFxVersion, classifier: &#39;win&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-base&#39;, version: javaFxVersion, classifier: &#39;mac&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-base&#39;, version: javaFxVersion, classifier: &#39;linux&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-controls&#39;, version: javaFxVersion, classifier: &#39;win&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-controls&#39;, version: javaFxVersion, classifier: &#39;mac&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-controls&#39;, version: javaFxVersion, classifier: &#39;linux&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-fxml&#39;, version: javaFxVersion, classifier: &#39;win&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-fxml&#39;, version: javaFxVersion, classifier: &#39;mac&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-fxml&#39;, version: javaFxVersion, classifier: &#39;linux&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: javaFxVersion, classifier: &#39;win&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: javaFxVersion, classifier: &#39;mac&#39;
implementation group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: javaFxVersion, classifier: &#39;linux&#39;

This allows a javafx gradle build to be run on any OS.

答案2

得分: 1

代码部分不要翻译,只返回翻译好的内容:

语法在Gradle中的确不正确。文档 会向您展示不同支持的语法。

最常见的两种是您使用的映射样式和使用 : 分隔的表示法。

所以以您的一个依赖项为例,您需要使用以下之一:

  • compile group: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2', classifier: 'win'
  • compile 'org.openjfx:javafx-graphics:11.0.2:win'

请注意,您还应该停止使用 compile 配置,改为使用 implementation。参见此解释以了解更多有关此主题的信息。

英文:

The syntax is indeed incorrect in Gradle. Documentation will show you the different supported syntax.

The two most common are the map style you used and the : separated notation.

So taking one of your dependency as an example, you need to use either:

  • compile group: &#39;org.openjfx&#39;, name: &#39;javafx-graphics&#39;, version: &#39;11.0.2&#39;, classifier: &#39;win&#39;
  • compile &#39;org.openjfx:javafx-graphics:11.0.2:win&#39;

Note that you should also stop using the compile configuration and instead use implementation. See this explanation to understand more on this topic.

huangapple
  • 本文由 发表于 2020年5月4日 02:36:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/61579722.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定