如何用gradle构建源代码jar [英] How to build sources jar with gradle

查看:468
本文介绍了如何用gradle构建源代码jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个用gradle构建的开源项目。我想生成一个(项目)-sources.jar文件,我可以加载到我的IDE(IntelliJ IDEA)并通过项目进行调试。我知道如何加载文件,如果我可以生成。



我已经浏览了该项目的可用gradle任务,并且没有一个生成源jar文件。



为这个项目生成源代码jar文件最简单的方法是什么?



添加源代码到包含编译后的类文件的jar文件中也可以。

任务sourcesJar(类型:Jar,dependsOn:类){
classifier ='sources'
from sourceSets.main.allSource
}

任务javadocJar(类型:Jar ,dependsOn:javadoc){
classifier ='javadoc'
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocJar
}


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.

I have looked through the available gradle tasks for the project and there isn't one that generates a sources jar file.

What is the easiest way to generate a sources jar file for this project?

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆