英文:
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:
<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>
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: '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'
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: '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'
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: 'org.openjfx', name: 'javafx-graphics', version: '11.0.2', classifier: 'win'
compile 'org.openjfx:javafx-graphics:11.0.2:win'
Note that you should also stop using the compile
configuration and instead use implementation
. See this explanation to understand more on this topic.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论