[英]Gradle : generating a jar from externally compiled classes
I'm trying to generate a jar
from a folder in which I manually compiled my classes. 我试图从一个文件夹中生成一个
jar
,在其中我手动编译了我的类。
Here is the task I put in place 这是我完成的任务
task toJar (type: Jar) {
from file('/path/to/classes/dir')
destinationDir file('/path/to/jars/dir')
with jar
}
But what that task doesn't generate anything. 但是那个任务不会产生任何东西。 I've seen may examples with
configurations.compile.collect
but in my case the directory is compiled by an external tool. 我已经看到了带有
configurations.compile.collect
示例,但是在我的情况下,目录是由外部工具编译的。
How gradle
can generate a jar
from externally compiled classes ? gradle
如何从外部编译的类生成jar
?
Your task should work fine, but you don't really need the with jar
. 您的任务应该可以正常运行,但实际上并不需要
with jar
。
Below is a working example, assuming that the directory with externally compiled classes is $rootDir/externalClasses
: 下面是一个工作示例,假定包含外部编译类的目录为
$rootDir/externalClasses
:
task toJar(type: Jar) {
from file("$rootDir/externalClasses")
destinationDir project.buildDir
// print each included file for debug purpose
eachFile { print "included file: $it" }
}
Output : 输出:
> Task :toJar
included file: file 'C:\tmp\gradle-projects\TestGradle\externalClasses\org\mycompany\gradle\MaiApp.class'
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
The result Jar file is then properly created in $buildDir/
然后在
$buildDir/
正确创建结果Jar文件。
Can you try to remove the "with jar" line, and add the eachFile
debug closure in your code? 您可以尝试删除“ with jar”行,并在代码中添加
eachFile
调试闭包吗? what is the output? 输出是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.