使用 Gradle 构建具有依赖项的 jar [英] Using Gradle to build a jar with dependencies
本文介绍了使用 Gradle 构建具有依赖项的 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多项目构建,我在其中一个子项目中放置了一个构建胖 jar 的任务.我创建的任务类似于在食谱中描述的任务.>
I have a multiproject build and I put a task to build a fat jar in one of the subprojects. I created the task similar to the one described in the cookbook.
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
manifest { attributes 'Main-Class': 'com.benmccann.gradle.test.WebServer' }
}
运行它会导致以下错误:
Running it results in the following error:
原因:您无法更改不在的配置未解决的状态!
Cause: You can't change a configuration which is not in unresolved state!
我不确定这个错误是什么意思.我也在 Gradle JIRA 上报告了这个,以防它是一个错误.
I'm not sure what this error means. I also reported this on the Gradle JIRA in case it is a bug.
推荐答案
我发布了一个解决方案 在针对 Gradle 的 JIRA 中:
I posted a solution in JIRA against Gradle:
// Include dependent libraries in archive.
mainClassName = "com.company.application.Main"
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
注意 mainClassName
必须出现在 jar {
之前.
Note that mainClassName
must appear BEFORE jar {
.
这篇关于使用 Gradle 构建具有依赖项的 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文