【发布时间】:2017-09-12 18:32:01
【问题描述】:
我看到以前有人问过这个问题。我很想看到答案,但它被删除了。冒着像那个帖子那样被否决的风险......,我真的需要帮助,因为我已经花了几天时间,我完全不知所措......
我有一个相当成熟的 java 项目。我们正准备从 alpha 阶段进入 beta 版本。作为其中的一部分,我们希望使用带有图标等的适当应用程序发布可安装包。使用 macAppBundle gradle 插件创建用于在 Mac 上分发的 (dmg) 包非常容易,而且效果很好。我现在正在尝试解决 Linux 上的分发问题。理想情况下,setupbuilder 插件将是可行的方法,但有一个错误阻止我创建 .deb 或 .rpm 包。我已将错误提交给开发人员,目前正在尝试通过关注this blog post 来解决此问题。
我在我的 Mac 上的 VirtualBox 中运行 Ubuntu 16.04.3 vm,我可以通过运行 gradle debianPrepareappname 成功创建一个工作可执行文件。但是当我尝试运行gradle debian 来创建.deb 文件时,构建总是失败(当前出现此错误:)。
Process 'command 'debuild'' finished with non-zero exit value 255
当我手动运行 debuild 时,我看到以下内容:
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发行版了。我知道 makefile 进行编译并将文件复制到系统中的位置,但我不知道创建 .deb 文件需要做什么或需要去哪里。我的意思是,必要的组件在那里并且它们工作:
appname/build/debian/appname/debian/{bin,lib}
bin 具有工作可执行文件,lib 具有所有必要的 jar 文件。我只是不知道我需要在 gradle 构建脚本中做什么来创建 .deb 文件。这是我在 gradle 构建文件中的内容(为了简单起见,我已经省略了 macAppBundle 和 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()
}
}
}
我读过的所有内容都表明使用 gradle 应该很容易。 macAppBundle 绝对是非常简单的——它就像 5 行代码。我几乎不需要阅读任何东西来弄清楚它,它创建了一个 dmg,其中包含一个带有图标的可执行文件和所有内容。我刚刚复制并编辑了 macAppBundle 自述文件中的示例。如果不是因为我遇到的错误,setupbuilder 看起来同样简单。是否有类似的示例可以为不使用 setupbuilder 的 java 项目构建 .deb 包?我尝试了其他几个插件都没有成功。我一直在谷歌搜索,除了我提到的博客文章之外,我找不到任何简单的东西。我最终想将一个图标应用于可执行文件和其他细节,但首先要做的是让它构建。那么为什么没有创建规则文件呢?这似乎是一个不错的起点。
【问题讨论】: