【问题标题】:How to create a debian distro for a java project using gradle如何使用 gradle 为 java 项目创建 debian 发行版
【发布时间】: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 包?我尝试了其他几个插件都没有成功。我一直在谷歌搜索,除了我提到的博客文章之外,我找不到任何简单的东西。我最终想将一个图标应用于可执行文件和其他细节,但首先要做的是让它构建。那么为什么没有创建规则文件呢?这似乎是一个不错的起点。

【问题讨论】:

    标签: java gradle debian


    【解决方案1】:

    我认为您缺少的是一个“debian”目录,其中包含所有相关文件。如果您从您提到的博客文章中查看 github 上的 syncany 的 repo https://github.com/syncany/syncany/tree/74c737d871d21dff5283edaac8c187a42c020b20/gradle/debian/debian,您会看到他有 8 个文件。

    归根结底,debuild 只是将一组文件捆绑到一个安装程序中。他们都必须在那里开始。他的脚本不会创建任何这些文件,只是修改一些,例如更改日志。

    【讨论】:

    • Debian 目录在那里,gradle 正在创建一个控制文件和一个变更日志文件,但没有规则文件?我实际上回到调试 setupbuilder 并走得更远。 “错误”只是我不知道缺少什么。但是,现在我遇到了其他问题。也许我对这一切都错了。我想要的只是从一个工作自包含的 jar 中创建一个可执行的应用程序,带有一个图标,它是某种可分发的格式——就像 macAppBundle 的 5 行代码一样。这可能吗?
    • 构建一个 .deb 并不会为您做到这一点。它只允许您将许多文件解压缩到正确的位置。创建启动脚本、文件关联等仍取决于您。
    • 我的理解是,这就是 gradle 的用途。它适用于 Mac(即在 .dmg 包中创建 .app)。事实上,不是使用 setupbuilder,而是使用应用程序插件,我可以让 gradle 创建一个 shell 脚本来启动 Java 应用程序,但我不知道如何使用 setupbuilder 或如何将其放入 .deb文件。
    • @Willa 时间太久了,我记不得了,但我会将您链接到该项目。它是开源和公开的。也许你可以解决它。 bitbucket.org/TreeView3Dev/treeview3/src/master
    • @hepcat72 你刚刚救了我的命。谢谢一百万。
    猜你喜欢
    • 2012-12-10
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    相关资源
    最近更新 更多