У меня есть простое java 9 и приложение Gradle. Я добавил внешнюю зависимость к приложению. Когда я пытаюсь запустить задачу gradle createFinalAppBundle
, я получаю следующую ошибку:
error: module not found: com.sun.jna
error: module not found: com.sun.jna.platform
Ниже приведена информация о моем модуле. java file
module in.abcd.launcher {
requires com.sun.jna.platform;
requires com.sun.jna;
exports in.abcd.launcher;
}
Ниже представлена вся моя файл gradle.build
apply plugin: 'java'
sourceCompatibility = 1.9
compileJava.options.encoding = 'UTF-8'
task wrapper(type: Wrapper) {
gradleVersion = '4.5.1'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile group: 'net.java.dev.jna', name: 'jna', version: '5.5.0'
compile group: 'net.java.dev.jna', name: 'jna-platform', version: '5.5.0'
}
def jdk = System.getProperty("java.home")
def moduleName = "in.abcd.launcher"
def mainClass = 'in.abcd.launcher.Launcher'
jar {
manifest {
attributes(
'Main-Class': mainClass,
)
}
}
// creates application bundle (executable + runtime)
task javaPackager(type: Exec, dependsOn: assemble) {
workingDir project.projectDir
commandLine = [
'javapackager',
'-deploy',
'-nosign',
'-native', 'image',
'-outdir', "${buildDir}/distribution",
'-outfile', project.name,
'-name', project.name,
'-appclass', mainClass,
'-p', "${jdk}/jmods${File.pathSeparator}${buildDir}/libs",
'--add-modules', moduleName,
'-m', "$moduleName/$mainClass"
]
}
// removes bloated runtime created by javapackager
task cleanPackagerRuntime(dependsOn: javaPackager) {
doLast() {
File runtimeFile = new File("${buildDir}/distribution/${project.name}/runtime")
runtimeFile.deleteDir()
System.out.println("deleting bloated runtime in " + runtimeFile)
}
}
// creates a replacement runtime via jlink command (much smaller than jpackager)
task createFinalAppBundle(type: Exec, dependsOn: [cleanPackagerRuntime]) {
workingDir project.projectDir
commandLine = [
'jlink',
'-p', "${jdk}/jmods${File.pathSeparator}${buildDir}/libs",
'--add-modules', moduleName,
'--strip-debug',
'--no-header-files',
'--no-man-pages',
'--strip-native-commands',
"--vm=server",
"--compress=2",
'--output', "${buildDir}/distribution/${project.name}/runtime"
]
doLast{
System.out.println("Application '${project.name}' packaged.")
System.out.println(" -> location: ${buildDir}/distribution/${project.name}/")
}
}