如何使用 gradle 构建源 jar? [英] How to build sources jar with gradle?
问题描述
我正在使用一个用 gradle 构建的开源项目.我想生成一个(项目)-sources.jar 文件,我可以将其加载到我的 IDE(IntelliJ IDEA)中并通过项目进行调试.如果可以生成文件,我知道如何加载它.
I am working with an open source project that is built with gradle. I would like to generate a (project)-sources.jar file that I can load into my IDE (IntelliJ IDEA) and debug through the project. I know how to load the file if I can generate it.
我已经查看了该项目可用的 gradle 任务,但没有一个可以生成源 jar 文件.
I have looked through the available gradle tasks for the project and there isn't one that generates a sources jar file.
为此项目生成源 jar 文件的最简单方法是什么?
What is the easiest way to generate a sources jar file for this project?
将源代码添加到包含已编译类文件的 jar 文件中也可以.
Adding the source into the jar file that contains the compiled class files would be fine as well.
推荐答案
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
这篇关于如何使用 gradle 构建源 jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!