Gradle部署Jar文件

时间:2014-09-23 12:43:08

标签: deployment jar gradle

我想创建一个build.gradle文件,将一些类打包到jar中,然后在某处部署这个jar。作为示例,我创建了一个类hello.class(经典HelloWorld)和一个build.gradle:

task hello(type : Jar) {
    archiveName = "hello.jar"
    destinationDir = file("/home/GradleTest")
    destFile = file("/home/GradleTest/hello.jar")
    from("/home/GradleTest") }

当我尝试启动gradle(gradle build)时,我收到此错误:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/GradleTest/build.gradle' line: 4

* What went wrong:
A problem occurred evaluating root project 'GradleTest'.
> No such property: destFile for class: org.gradle.api.tasks.bundling.Jar_Decorated

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.153 secs

有谁知道这是什么问题?我告诉你gradle -v命令的结果:

------------------------------------------------------------
Gradle 2.0
------------------------------------------------------------

Build time:   2014-07-01 07:45:34 UTC
Build number: none
Revision:     b6ead6fa452dfdadec484059191eb641d817226c

Groovy:       2.3.3
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_51 (Oracle Corporation 24.51-b03)
OS:           Linux 3.13.0-24-generic amd64

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:0)

没有destFile这样的属性。您可以使用archiveFile。它将为您提供此值而无需分配它。至少这是我在查看文档时看到的内容 - http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html

答案 1 :(得分:0)

我设法做到了(感谢@radim的回答)

task createJar(type : Jar) {
    def originDir = file("${buildDir}/unpacked")
    def destinationFile = "${buildDir}/repackaged/${project.name}-${version}"
    archiveName = destinationFile
    from(originDir)
    archiveFile
}