以下是从现有项目复制,并可以使用一些事情不包括在片段(如星云插件):
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = 'com.example.Main'
jar {
manifest {
attributes 'Main-Class': 'com.example.Main'
}
}
publishing {
publications {
nebulaIvy(IvyPublication) {
artifact(tasks.findByName('createJarExe').outputs.getFiles().getSingleFile()) {
classifier '_-jdk8'
extension 'exe'
type 'exe'
}
}
}
}
task createJarExe(dependsOn: installShadowDist) {
final outputFile = file("${buildDir}/install/${project.name}-shadow/bin/${project.name}-${project.version}.exe")
doLast {
outputFile.text = '#!/bin/bash\n'
outputFile.append('exec java -jar "$0" "[email protected]"')
outputFile.append(inputs.files.first().readBytes())
outputFile.setExecutable(true)
}
inputs.files "${tasks.findByName('installShadowDist').outputs.getFiles().getSingleFile()}/lib/${project.name}-${project.version}-all.jar"
outputs.file outputFile
doFirst {
mkdir outputFile.getParent()
}
}
// wire the dependencies
tasks.whenTaskAdded { task ->
if (task.name == 'publishNebulaIvyPublicationToDistIvyRepository') {
task.dependsOn('createJarExe')
}
}
注:
com.github.johnrengelman.shadow
用于创建尤伯杯-罐。
com.example.Main
是执行的Java入口点。
- 指定
classifier
对于protoc
Gradle插件(其中默认包含classifier
中的操作系统)更多,不是严格需要。已发布的protoc
插件的客户端必须使用版本0.8.3
及更高版本的protoc
Gradle插件,该插件支持覆盖classifier
。
createJarExe
使用尤伯杯罐子,如下http://en.newinstance.it/2012/04/17/self-executing-jar-files/#
wire the dependencies
确保尤伯杯罐子分配之前创建
可能相关:https://stackoverflow.com/q/3445825/1531971 – jdv
是,这是相关但不足。问题是一个jar不能有一个'CLASSPATH'来引用它自己内部的jar。 –
哦,对。这是响亮的一些钟声。作为一名Gradle牧牛人是不讨好的。 – jdv