Skip to content

Commit 8b8083b

Browse files
committed
Add Add-Opens to JAR manifest
This means that running the JAR via `java -jar` will not require a bunch of `--add-opens` flags to be manually added on the command line. The set of modules is defined in one list, then: - Compiled into the JAR/shadow JAR manifest's `Add-Opens` list - Added as `--add-opens` command line options for running from Gradle or the JPackage.
1 parent 108f82c commit 8b8083b

1 file changed

Lines changed: 32 additions & 30 deletions

File tree

build.gradle

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,37 @@ ext {
9292
println "OS Detected: " + osdetector.os
9393
}
9494

95+
def modulesToOpen = [
96+
'java.desktop/java.awt',
97+
'java.desktop/java.awt.geom',
98+
'java.desktop/sun.awt.geom',
99+
'java.base/java.util',
100+
'javafx.web/javafx.scene.web',
101+
'javafx.web/com.sun.webkit',
102+
'javafx.web/com.sun.webkit.dom',
103+
'java.base/java.lang',
104+
'java.desktop/sun.awt',
105+
'java.desktop/sun.java2d',
106+
'java.desktop/javax.swing',
107+
'java.desktop/sun.awt.shell',
108+
]
109+
def jarManifestAttributes = [
110+
'Implementation-Title': project.name + developerRelease,
111+
'Implementation-Version': tagVersion,
112+
'Implementation-Vendor': vendor,
113+
'Git-Commit': revision,
114+
'Git-Commit-SHA': revisionFull,
115+
'Built-By': System.getProperty('user.name'),
116+
'Built-Date': new Date(),
117+
'Built-JDK': System.getProperty('java.version'),
118+
'Source-Compatibility': project.java.sourceCompatibility,
119+
'Target-Compatibility': project.java.targetCompatibility,
120+
'Main-Class': project.application.mainClass,
121+
'Add-Opens': modulesToOpen.join(' '),
122+
]
95123
def javaArgs = [
96124
"-Xss8M",
97-
"--add-opens=java.desktop/java.awt=ALL-UNNAMED", "--add-opens=java.desktop/java.awt.geom=ALL-UNNAMED",
98-
"--add-opens=java.desktop/sun.awt.geom=ALL-UNNAMED", "--add-opens=java.base/java.util=ALL-UNNAMED",
99-
"--add-opens=javafx.web/javafx.scene.web=ALL-UNNAMED", "--add-opens=javafx.web/com.sun.webkit=ALL-UNNAMED",
100-
"--add-opens=javafx.web/com.sun.webkit.dom=ALL-UNNAMED","--add-opens=java.base/java.lang=ALL-UNNAMED",
101-
"--add-opens=java.desktop/sun.awt=ALL-UNNAMED", "--add-opens=java.desktop/sun.java2d=ALL-UNNAMED",
102-
"--add-opens=java.desktop/javax.swing=ALL-UNNAMED","--add-opens=java.desktop/sun.awt.shell=ALL-UNNAMED",
103-
"--add-opens=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED"]
125+
] + modulesToOpen.collect { '--add-opens=' + it + '=ALL-UNNAMED' }
104126

105127
// Used by gradle assemble & run tasks
106128
application {
@@ -442,36 +464,16 @@ shadowJar {
442464
archiveClassifier = null
443465

444466
manifest {
445-
attributes 'Implementation-Title': project.name + developerRelease,
446-
'Implementation-Version': tagVersion,
447-
'Implementation-Vendor': vendor,
448-
'Git-Commit': revision,
449-
'Git-Commit-SHA': revisionFull,
450-
'Built-By': System.getProperty('user.name'),
451-
'Built-Date': new Date(),
452-
'Built-JDK': System.getProperty('java.version'),
453-
'Source-Compatibility': project.java.sourceCompatibility,
454-
'Target-Compatibility': project.java.targetCompatibility,
455-
'Main-Class': project.application.mainClass,
456-
'Multi-Release': true
467+
attributes jarManifestAttributes
468+
attributes 'Multi-Release': true
457469
}
458470

459471
exclude 'module-info.class' //This is to make sure maptool doesn't become a module by including module-info of dependencies. Probably needs to be fixed before we go to jdk 11+
460472
}
461473

462474
jar {
463475
manifest {
464-
attributes 'Implementation-Title': project.name + developerRelease,
465-
'Implementation-Version': tagVersion,
466-
'Implementation-Vendor': vendor,
467-
'Git-Commit': revision,
468-
'Git-Commit-SHA': revisionFull,
469-
'Built-By': System.getProperty('user.name'),
470-
'Built-Date': new Date(),
471-
'Built-JDK': System.getProperty('java.version'),
472-
'Source-Compatibility': project.java.sourceCompatibility,
473-
'Target-Compatibility': project.java.targetCompatibility,
474-
'Main-Class': project.application.mainClass
476+
attributes jarManifestAttributes
475477
}
476478
}
477479

0 commit comments

Comments
 (0)