多读书多实践,勤思考善领悟

JavaFX 11+ controlsfx的build.gradle

本文于1798天之前发表,文中内容可能已经过时。

我们无法摆脱所有这些--add-opens--add-exports因为许多控制将不得不去。

您可以在build.gradle文件中找到运行示例所需的所有jvm args的列表。您的应用程序需要根据您使用的内容添加其中一些。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
ext.java9Args = [
// For various usages of TraversalEngine
"--add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls",
"--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
// For FontAwesome Style
"--add-exports=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls",
// For various behaviors across controls
"--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls",
// For ReadOnlyUnbackedObservableList across files
"--add-exports=javafx.controls/com.sun.javafx.scene.control=org.controlsfx.controls",
// For InputMap used in behavior classes
"--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=org.controlsfx.controls",
// For EventHandlerManager across files
"--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls",
// For MappingChange, NonIterableChange across files
"--add-exports=javafx.base/com.sun.javafx.collections=org.controlsfx.controls",
// For VersionInfo in VersionChecker
"--add-exports=javafx.base/com.sun.javafx.runtime=org.controlsfx.controls",
// For WebPage in SVGLoader
"--add-exports=javafx.web/com.sun.webkit=org.controlsfx.controls",
// For enabling FontAwesome
"--add-exports=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls"
]

ext.java9RuntimeArgs = [
// For accessing VirtualFlow field from the base class in GridViewSkin
"--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls",
// For accessing getChildren in ImplUtils
"--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls"
]

static String getOSName() {
final String osName = System.getProperty("os.name").toLowerCase()
if (osName.contains("linux")) {
return ("linux")
} else if (osName.contains("mac os x") || osName.contains("darwin") || osName.contains("osx")) {
return ("mac")
} else if (osName.contains("windows")) {
return ("win")
}
return ("")
}

ext.javafx_modules = [
'javafx-base',
'javafx-graphics',
'javafx-controls',
'javafx-fxml',
'javafx-media',
'javafx-web'
]

if (JavaVersion.current().isJava11Compatible()) {
ext.javafx_version = '11'
ext.platform = getOSName()
}

subprojects {

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'osgi'
apply plugin: 'maven'
apply from : '../mavenPublish.gradle'

Properties cfg = new Properties()
cfg.load(new FileInputStream("$rootDir/controlsfx-build.properties"))

ext {
artifact_suffix = cfg.artifact_suffix
specification_title = cfg.controlsfx_specification_title //'Java 8u20'
specification_version = cfg.controlsfx_specification_version //'8.20.7'
controlsfx_name = 'controlsfx'
fxsampler_name = 'fxsampler'
fxsampler_version = cfg.fxsampler_specification_version + artifact_suffix
fxsampler_mainClass = 'org.controlsfx.fxsampler/fxsampler.FXSampler'
}

group = 'org.controlsfx'
version = specification_version + artifact_suffix

sourceCompatibility = '1.9'
targetCompatibility = '1.9'

if (JavaVersion.current().isJava11Compatible()) {
sourceCompatibility = rootProject.javafx_version
targetCompatibility = rootProject.javafx_version
}

afterEvaluate {

repositories {
mavenCentral()
}

dependencies {
testCompile 'junit:junit:[4,)'
}

test {
testLogging {
// Show that tests are run in the command-line output
events 'started', 'passed'
}
inputs.property("moduleName", moduleName)
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath,
]
classpath = files()
}
}

compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs += [
'--module-path', classpath.asPath,
]
classpath = files()
}
options.encoding = "UTF-8"
options.incremental = true
if ( project.name != "fxsampler" ) {
options.compilerArgs += java9Args
}
}

javadoc {
inputs.property("moduleName", moduleName)
doFirst {
exclude '**/module-info.java'
exclude 'impl/*'
options.addStringOption('-module-path', classpath.asPath)
options.addStringOption('-class-path', "")
options.addBooleanOption('html5', true)
options.addBooleanOption('javafx', true)
options.addBooleanOption('Xdoclint:none', true)
options.encoding = 'UTF-8'
javafx_modules.stream()
.map { module -> module.replace("-", ".") }
.each {
options.addStringOption('-add-modules', it)
}
// TODO: Uncomment once Javadoc link is fixed for JDK 11
/*if (JavaVersion.current().java11Compatible) {
options.links("https://openjfx.io/javadoc/11")
options.links("https://docs.oracle.com/en/java/javase/11/docs/api")
} else {*/
options.links("https://docs.oracle.com/javase/9/docs/api")
// }
// Only required JDK 9/10
options.addMultilineStringsOption("-add-exports").setValue(
[
'javafx.base/com.sun.javafx.event=ALL-UNNAMED',
'javafx.web/com.sun.webkit=ALL-UNNAMED',
'javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED'
]
)
}
}
}

task sourceJar(type: Jar) {
from sourceSets.main.java
from sourceSets.main.resources
classifier = 'sources'
}

task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
classifier = 'javadoc'
}

artifacts {
archives sourceJar
archives javadocJar
}

application {
applicationDefaultJvmArgs = [
'--add-opens=javafx.base/com.sun.javafx.runtime=ALL-UNNAMED',
'--add-opens=javafx.base/com.sun.javafx.collections=ALL-UNNAMED',
'--add-opens=javafx.graphics/com.sun.javafx.css=ALL-UNNAMED',
'--add-opens=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED',
'--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED',
'--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED',
'--add-opens=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED',
'--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED',
'--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED'
]
}
}