如何使用gradle为java项目创建debian发行版
我看到以前有人问过这个问题。我很想看到答案,但它被删除了。冒着像那个帖子一样被否决的风险,我真的需要帮助,因为我已经花了几天时间在上面了,我完全不知所措 我有一个相当成熟的java项目。我们正准备从alpha阶段进入beta版本。作为其中的一部分,我们希望发布带有图标等适当应用程序的可安装软件包。使用macAppBundle gradle插件创建(dmg)软件包在Mac上分发非常简单,而且工作非常出色。我现在正试图解决Linux上的分发问题。理想情况下,setupbuilder插件将是一个不错的选择,但有一个bug阻止我创建.deb或.rpm包。我向开发人员提交了这个bug,目前正试图通过以下方式解决这个问题 我正在Mac上的VirtualBox中运行一个Ubuntu 16.04.3虚拟机,通过运行如何使用gradle为java项目创建debian发行版,java,gradle,debian,Java,Gradle,Debian,我看到以前有人问过这个问题。我很想看到答案,但它被删除了。冒着像那个帖子一样被否决的风险,我真的需要帮助,因为我已经花了几天时间在上面了,我完全不知所措 我有一个相当成熟的java项目。我们正准备从alpha阶段进入beta版本。作为其中的一部分,我们希望发布带有图标等适当应用程序的可安装软件包。使用macAppBundle gradle插件创建(dmg)软件包在Mac上分发非常简单,而且工作非常出色。我现在正试图解决Linux上的分发问题。理想情况下,setupbuilder插件将是一个不错的
gradle debianPrepareappname
,我可以成功地创建一个工作的可执行文件。但是,当我尝试运行gradledebian
来创建.deb文件时,构建总是失败(当前出现此错误:)
Process'command'debuild''以非零退出值255完成
手动运行Debild时,我会看到以下内容:
debuild: fatal error at line 679:
found debian/changelog in directory
/home/username/appname/build/debian/appname
but there's no debian/rules there! Are you in the source code tree?
gradle未创建任何规则文件。我知道规则文件基本上是一个makefile。。。一般来说,我对makefile不是很熟悉,更不用说创建.deb发行版了。我知道makefiles进行编译并将文件复制到系统中的某个位置,但我不知道创建.deb文件需要做什么,也不知道需要做什么。我的意思是,必要的组件就在那里,它们可以工作:
appname/build/debian/appname/debian/{bin,lib}
bin
具有工作的可执行文件,lib
具有所有必要的jar文件。我只是不知道我需要在gradle构建脚本中做什么来创建.deb文件。下面是我在gradle构建文件中得到的内容(为了简单起见,我省略了macAppBundle和setupbuilder的内容,它们现在只是残留在那里):
apply插件:“java”
应用插件:“eclipse”
应用插件:“应用程序”
defaultTasks“clean”、“fatJar”、“eclipse”
version=getVersionName()
sourceCompatibility=1.7
targetCompatibility=1.7
存储库{
mavenCentral()
}
依赖关系{
编译'com.miglaway:miglaway swing:5.0'
编译'com.googlecode.plist:dd plist:1.3'
编译“org.freehep:freehep graphicsio:2.4”
编译“org.freehep:freehep graphicsio pdf:2.4”
编译“org.freehep:freehep-graphicsio-ps:2.4”
编译“org.freehep:freehep graphicsio svg:2.4”
编译“org.freehep:freehep-graphics2d:2.4”
编译“org.swinglabs.swingx:swingx自动完成:1.6.5-1”
}
源集{
主要{
爪哇{
srcDir'src/main/java/'
}
}
}
任务fatJar(类型:Jar){
显示{
属性'Main Class':'com.placeholder.appname'
}
baseName=project.name+'-all'
从{configurations.compile.collect{it.isDirectory()?it:zipTree(it)}
用罐子
}
def getVersionName(){
def stdout=newbytearrayoutputstream()
执行官{
命令行'git','revparse','--short','HEAD'
标准输出=标准输出
}
返回stdout.toString().trim()
}
字符串applicationVersionFull=getVersionName()
任务debianClean(类型:删除){
删除“build/debian”
}
tasks.addRule(“模式:debianPrepare”){String taskName->
if(taskName.startsWith(“debianPrepare”)){
任务(任务名,dependsOn:[installDist,debianClean]){
字符串debianDistribution=(任务名-“debianPrepare”).toLowerCase()
字符串DebiaApplicationVersionFull=getVersionName()
多拉斯特{
抄袭{
来自rootProject.files(“build/install/appname”)
文件(“build/debian/appname”)
}
抄袭{
来自rootProject.files(“gradle/debian/debian”)
文件(“build/debian/appname/debian”)
}
}
}
}
}
任务debian{//取决于debianPrepare*
多拉斯特{
执行官{
workingDir rootProject.file(“build/debian/appname”)
命令行“debuild-i-us-uc-b”.split()
}
}
}
我读到的所有东西都说这对gradle来说应该很容易。macAppBundle绝对是非常简单的——它就像5行代码。我几乎不需要阅读任何东西来理解它,它创建了一个dmg,它有一个带有图标的可执行文件和所有东西。我刚刚复制并编辑了macAppBundle自述文件中的示例。如果不是因为我遇到的bug,setupbuilder看起来也很简单。对于不使用setupbuilder的java项目,是否有类似的构建.deb包的例子?我尝试了其他几个插件,但没有成功。我一直在谷歌上搜索,除了我提到的博文,我找不到任何直接的东西。我最终希望在可执行文件和其他细节上应用一个图标,但首先要做的是让它生成。那么为什么不创建规则文件呢?这似乎是一个很好的起点。我认为您缺少的是一个“debian”目录,其中包含所有相关文件。如果你从你提到的博客文章中查看syncany在github上的repo,你会发现他有8个文件
最终,Debild只是将一组文件捆绑到安装程序中。首先,他们都必须在那里。他的脚本不创建这些文件中的任何一个,只是修改一些文件,比如变更日志。Debian目录在那里,gradle正在创建一个控制文件和变更日志文件,但没有规则文件?实际上,我又回到了调试setupbuilder,并做了一些进一步的工作。“错误”只是我不知道遗漏了什么。然而,现在我遇到了其他问题。也许我整个晚上都在做这件事
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
defaultTasks "clean", "fatJar", "eclipse"
version = getVersionName()
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
mavenCentral()
}
dependencies {
compile 'com.miglayout:miglayout-swing:5.0'
compile 'com.googlecode.plist:dd-plist:1.3'
compile 'org.freehep:freehep-graphicsio:2.4'
compile 'org.freehep:freehep-graphicsio-pdf:2.4'
compile 'org.freehep:freehep-graphicsio-ps:2.4'
compile 'org.freehep:freehep-graphicsio-svg:2.4'
compile 'org.freehep:freehep-graphics2d:2.4'
compile 'org.swinglabs.swingx:swingx-autocomplete:1.6.5-1'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
task fatJar(type: Jar) {
manifest {
attributes 'Main-Class':'com.placeholder.appname'
}
baseName = project.name + '-all'
from {configurations.compile.collect {it.isDirectory() ? it : zipTree(it)}}
with jar
}
def getVersionName() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
String applicationVersionFull = getVersionName()
task debianClean(type: Delete) {
delete 'build/debian'
}
tasks.addRule("Pattern: debianPrepare<distribution>") { String taskName ->
if (taskName.startsWith("debianPrepare")) {
task(taskName, dependsOn: [installDist, debianClean]){
String debianDistribution = (taskName - "debianPrepare").toLowerCase()
String debianApplicationVersionFull = getVersionName()
doLast {
copy {
from rootProject.files("build/install/appname")
into rootProject.file("build/debian/appname")
}
copy {
from rootProject.files("gradle/debian/debian")
into rootProject.file("build/debian/appname/debian")
}
}
}
}
}
task debian { // depends on debianPrepare*
doLast {
exec {
workingDir rootProject.file("build/debian/appname")
commandLine "debuild -i -us -uc -b".split()
}
}
}