首页 \ 问答 \ Gradle部署Jar文件(Gradle deploying a Jar file)

Gradle部署Jar文件(Gradle deploying a Jar file)

我想创建一个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

非常感谢你的帮助。


I would like to create a build.gradle file to pack some classes into a jar and deploy this jar somewhere. As an example, I created a class hello.class (classic HelloWorld) and a build.gradle:

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

When I try launch gradle (gradle build), I get this error:

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

Does anyone know what is the problem? I give you the result of my gradle -v command:

------------------------------------------------------------
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

Thank you much for your help.


原文:https://stackoverflow.com/questions/25995430
更新时间:2021-06-05 21:06

最满意答案

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


There is no such property as destFile. You can use archiveFile. It will give you this value without the need to assign it. At least that's what I see when I look at the documentation - http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html

相关问答

更多

在构建时使用gradle在项目中包含本地jar文件(Including local jar file in project at build time using gradle)

这在文档中有解释。 以下应该做的是: dependencies { compile files('./src/main/resources/enterprise.jar') } 尽管如此,我不会把jar放在src/main/resources 。 它不是您项目的资源,而是编译依赖项。 我会把它放在一个lib目录中。 This is explained in the documentation. The following should do: dependencies { com ...

Java插件中的Gradle - jar文件名(Gradle - jar file name in java plugin)

默认项目名称取自存储项目的目录。不要明确更改jar名称,而应将项目名称设置为您的构建的正确名称。 目前这在build.gradle文件中是不可能的。 相反,您必须在根目录中创建settings.gradle文件。 这个settings.gradle文件应该包含这一行代码: rootProject.name = 'project1' The default project name is taken from the directory the project is stored in. Inst ...

Gradle artifactoryPublish不会部署spring boot生成的.jar文件(Gradle artifactoryPublish won't deploy .jar file generated by spring boot)

你的publishing区有一个非常微妙的错误。 from is missing导致Gradle无法在发布中包含jar文件。 您需要更新publishing块,使其如下所示: publications { mavenJava(MavenPublication) { from components.java } } 如果我是你,我会为此打开一个Gradle可用性错误。 默默无所事事不是非常用户友好。 There's a very subtle mistake in ...

将jar文件从多项目gradle构建部署到目标目录(Deploy jar files from multi-project gradle build to destination directory)

您只需将以下代码添加到project1和project2 : jar { destinationDir project.file('../dest') } 编辑 (在评论中讨论后) 您需要将以下代码添加到root build.gradle文件中 subprojects { apply plugin: 'java' } task copyFiles(type: Copy, dependsOn: subprojects.jar) { from(subprojects.jar) ...

从Gradle构建文件中调用Ant jar目标(Call Ant jar target from Gradle build file)

Gradle仅在您应用Java插件时添加jar任务,您不应该为导入Ant构建的项目执行该操作。 我认为您不应该从Gradle构建脚本调用ant.project.addTarget 。 Gradle only adds a jar task when you apply the Java plugin, which you shouldn't do for the project into which you import the Ant build. I don't think you shoul ...

Gradle部署Jar文件(Gradle deploying a Jar file)

没有像destFile这样的属性。 您可以使用archiveFile 。 它将为您提供此值而无需分配它。 至少这是我在查看文档时看到的内容 - http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html There is no such property as destFile. You can use archiveFile. It will give you this value without t ...

如何将JAR文件添加到现有的gradle项目?(How to add a JAR file to an existing gradle project?)

compile files('/<ABSOLUTE_PATH>/<DEPENDENCY>.jar') or //put jar file in lib directory of project. compile fileTree(dir: 'lib', includes: ['*.jar']) } compile files('/<ABSOLUTE_PATH>/<DEPENDENCY>.jar') or //put jar file in lib directory of project. co ...

如何使用gradle在编译阶段添加依赖jar文件?(How to add dependency jar files during compiling stage using gradle?)

我终于找到了解决方案。 Gradle构建有三个不同的阶段: 初始化 组态 执行 依赖块将在配置阶段执行。 因此,要在依赖关系块中使用依赖关系jar,必须在初始化阶段或配置阶段但在依赖关系阻止执行之前下载依赖关系jar。 就我而言,不使用初始化阶段。 所以我必须确保在依赖项阻止之前下载依赖jar。 简单地说,调整块序列就可以了。 apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion "19. ...

具有conf文件夹的Gradle构建文件,其属性不在jar中但在classpath上(Gradle build file with conf folder with properties not in jar but on classpath)

正如这里提到的Gradle distZip配置文件,您可以将文件夹dist/config添加到您的src文件夹,它将自动包含在distZip任务中。 至于将它添加到运行时类路径中,只需将该文件夹添加为依赖项(参见下文)。 由于startScripts限制,要求#2 startScripts 。 这个问题的答案提出了一种解决方法,但是: 使用Gradle的Application插件添加类路径条目 以下代码收集了以上所有内容: // put config files in src/dist/confi ...

Docker同时使用Jar和Gradle执行jenkins(Docker with both Jar and Gradle executions in it for jenkins)

我不确定我是否正确理解你的要求,但希望我能提供一些帮助。 您不能有两个入口点停靠图像,但您仍然至少有两个关于如何在图像上运行两个命令的选择。 1)为您的jarrunner映像创建一个启动脚本,并将其用作入口点。 脚本应首先运行jar文件(名称作为命令行参数或环境变量给出),然后运行test命令。 2)像现在一样使用jarrunner图像。 当容器运行时,使用docker exec <container id/name> gradle AcceptanceTest在同一容器上运行另一个命令。 I'm ...

相关文章

更多

最新问答

更多
  • 如何从远程文件拉取文件而不覆盖本地文件?(How do I pull files from remote without overwriting local files?)
  • Reactjs:状态改变时重新渲染iframe(Reactjs: re-renders iframes when state changed)
  • 奇怪的网址,以及跟随php页面流程的困难(odd url, and difficulty in following the php page flow)
  • 标签活动无效(Tab Activity is not working)
  • JavaME合适的语法编译器建议?(JavaME-suitable grammar compiler recommendations?)
  • 指定参数(Specifying arguments)
  • 可以通过Ruby插件或控制台覆盖Sketchup中的键盘快捷键吗?(Can one override keyboard shortcuts in Sketchup through the a Ruby Plugin or Console?)
  • 计算Java EE Web App中用户数的最佳方法(Best way to count number of users in a Java EE web App)
  • 无法使用templateUrl加载cordova中的外部模板(unable to load external templates in cordova with templateUrl)
  • PHPExcel:写入期间无法使用缓存(PHPExcel: Unable to use cache during write)
  • 在javascript中嵌套这个指针(nested this pointer in javascript)
  • 谁跟领航致远培训过,有问题问下啊
  • 控制器要求在入门时下载(Controller ask to download on entry)
  • 未能通过conda安装Asyncio(Failure to install Asyncio via conda)
  • 如何查找已完成项目的总长度?(How to find length of total completed items?)
  • 如何检查OleInitialize是否已被调用?(How to check if OleInitialize has already been called?)
  • SQL在特定范围内返回列中具有最大值的行(SQL Returning rows with max value in column, within a specific range)
  • preg_match从url获取id(preg_match get the id from url)
  • 如何在运算符中为make方程转换perl变量?(How to convert a perl variable in a operator for make equations?)
  • 在导航上方添加空格/标题。(Add a white space/ header above navigation.)
  • MeetingItem已保存;(MeetingItem saved; but change now shown in Calendar)
  • c#vb:我们应该使用System.Lazy进行资源密集型任务吗?(c# vb: Should we use System.Lazy for resource-intensive task? (when threading is not needed))
  • 为什么在armeabi代码中使用armeabi-v7a代码?(Why use armeabi-v7a code over armeabi code?)
  • 获取请求的自定义标头(Java HTTP)(Fetching a custom header of a request (Java HTTP))
  • 是否可以在嵌套的if语句中从varchar转换为numeric以动态评估参数?(Is it possible to convert from varchar to numeric within a nested if statement in order to dynamically evaluate a parameter?)
  • 如何将Html.ActionLink转换为链接到Ajax调用的按钮?(How to convert from Html.ActionLink to a button linked to Ajax call?)
  • 应用程序如何处理Windows符号链接?(How are Windows symbolic links treated by the apps?)
  • html,js,css在jsfiddle中工作,但不在sharepoint中(html, js, css works in jsfiddle but not in sharepoint)
  • 从Ruby脚本调用Elasticsearch Rest API(Calling Elasticsearch Rest API from Ruby script)
  • 如何将嵌套setTimeouts转换为承诺(How to convert nested setTimeouts to promises)