gradle:自定义 jar 任务
我觉得我在这里遗漏了一些明显的东西,但我似乎找不到它。
我有一个项目,我希望我的包结构像这样,所以
/src
/webapp
/webapp-package-1
/webapp-package-2
/iface
/iface-package-1
/iface-package-2
我想定义一个任务来打包 iface 的类并将其放入 jar 中。所以我在这里遵循了用户指南: http://www.gradle.org /0.8/docs/userguide/userguide_single.html#configureSourceSet(我使用的是0.8版本)。
我现在有了这个,
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'src'
}
}
intTest {
java {
srcDir 'src/iface/'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
resources {
srcDir 'src'
}
}
}
task intTestJar(type: Jar, dependsOn: intTestClasses) {
from sourceSets.intTest.classes
}
并且可以验证 intTest
中的类是否在 /build/classes/intTest
中正确构建。但是,尝试调用 intTestJar
总是给我这个警告:
[ant:jar] Warning: skipping jar archive C:\workspace\foo\build\libs\foo-1.0.jar because no files were included.
我不明白这一点,因为类已成功创建。此外,完整构建任务成功创建了整个 jar。
有想法吗?
I feel like I am missing something obvious here, but I can't seem to find it.
I have a project, where I want my package structure like so
/src
/webapp
/webapp-package-1
/webapp-package-2
/iface
/iface-package-1
/iface-package-2
I want to define a task that packages up the classes for iface and makes it into a jar. So I followed the user guide here: http://www.gradle.org/0.8/docs/userguide/userguide_single.html#configureSourceSet (I am using version 0.8).
I now have this,
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'src'
}
}
intTest {
java {
srcDir 'src/iface/'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
resources {
srcDir 'src'
}
}
}
task intTestJar(type: Jar, dependsOn: intTestClasses) {
from sourceSets.intTest.classes
}
And can verify that the classes in intTest
are being built appropriately in /build/classes/intTest
. However, trying to invoke the intTestJar
always gives me this warning:
[ant:jar] Warning: skipping jar archive C:\workspace\foo\build\libs\foo-1.0.jar because no files were included.
I don't understand this, because the classes are being created successfully. Also, the full build task creates the entire jar successfully.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该解决方案似乎适用于最新版本的 Gradle(0.9.2)。我在这个文件树上完全按照上面所示运行了 intTestJar 任务(当然添加了 java 插件):
这是生成的 jar 结构:
所以简短的答案 - 尝试更新版本的 Gradle。 http://gradle.org/
This solution appears to work with the latest version of Gradle(0.9.2). I ran the intTestJar task exactly as shown above(adding the java plugin of course) on this file tree:
and here's the resulting jar structure:
So the short answer - try a newer version of Gradle. http://gradle.org/