如何使用gradle

时间:2017-09-12 18:32:01

标签: java gradle debian

我之前有人问过这个问题。我本来希望看到答案,但它被删除了。冒着像那个帖子那样被投票的风险......,我真的需要帮助,因为我已经花了几天时间而且我已经完全不知所措......

我有一个相当成熟的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()
        }
    }
}

我读过的所有内容都说这应该是非常容易的。 macAppBundle绝对非常简单 - 就像5行代码一样。我几乎不需要阅读任何东西来弄清楚它并创建了一个带有图标和所有内容的可执行文件的dmg。我只是复制了&amp;编辑了macAppBundle自述文件中的示例。如果不是因为我遇到的错误,setupbuilder看起来同样容易。是否有类似的例子用于为不使用setupbuilder的java项目构建.deb包?我尝试过其他一些插件但没有成功。我一直在谷歌搜索,除了我提到的博客文章,我找不到任何简单的东西。我最终想将一个图标应用于可执行文件和其他细节,但首先要做的就是构建它。那么为什么不创建规则文件呢?这似乎是一个很好的起点。

1 个答案:

答案 0 :(得分:0)

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

在一天结束时,debuild只是将一组文件捆绑到安装程序中。他们都必须在那里开始。他的脚本不会创建任何这些文件,只需修改一些文件,例如changelog。