如何使用gradle复制所有源码罐 [英] how to copy all source jars using gradle

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

问题描述

我们有一个旧的playframework 1.2.x版本,我们将所有的jar复制到project / lib中,以便playframework可以使用它们。我们很乐意复制所有的源代码jar,所以当runnig玩eclipsify时,我们可以查看所有的第三方源代码。有没有办法用gradle来做到这一点?

我的意思是我在运行gradle eclipse时下载的所有源代码jar,因为我看到它们下载缓存位置。我们在一个项目中使用gradle eclipse为我们调用了eclipsify,所以我们可以100%使用gradle。



谢谢,
Dean

解决方案

这并不像预期那样简单。以下片段将Java项目的所有依赖项(运行时+编译)的源jar复制到特定文件夹中:

 任务copySourceJars (type:Copy){
def deps = configurations.runtime.incoming.dependencies.collect {dependency - >
dependency.artifact {artifact - >
artifact.name = dependency.name
artifact.type ='source'
artifact.extension ='jar'
artifact.classifier ='sources'
} $ (配置.detachedConfiguration(deps依赖[])。resolvedConfiguration.lenientConfiguration.getFiles(Specs.SATISFIES_ALL))
('sourceLibs')



b}

这里我们使用lenientConfiguration的原因是,我们不想失败,如果源神器无法解析。可能有一种更优雅的方式,但我没有深入了解这一点。



希望它有帮助,



René


We have an old playframework 1.2.x version where we copy all the jars to project/lib so playframework can consume them. We would LOVE to copy all the source jars as well so that when runnig play eclipsify, we can view all the third party source. Is there a way to do this with gradle?

and I mean all the source jars that were downloaded when I ran gradle eclipse as I saw them download the cache locations. We have gradle eclipse calling play eclipsify for us on the one project as well so we can 100% just use gradle.

thanks, Dean

解决方案

this is not that straight forward as expected. The following snippet copies the source jars for all dependencies (runtime + compile) of a java project into a specific folder:

    task copySourceJars(type:Copy){
        def deps = configurations.runtime.incoming.dependencies.collect{ dependency ->
            dependency.artifact { artifact ->
                    artifact.name = dependency.name
                    artifact.type = 'source'
                    artifact.extension = 'jar'
                    artifact.classifier = 'sources'
                }
            dependency
        }
        from(configurations.detachedConfiguration(deps as Dependency[]).resolvedConfiguration.lenientConfiguration.getFiles(Specs.SATISFIES_ALL))
        into('sourceLibs')
    }

The reason we use a lenientConfiguration here is, that we don't want to fail if a source artifact cannot be resolved. There might be a more elegant way, but I havn't looked deeper into that.

hope it helps,

René

这篇关于如何使用gradle复制所有源码罐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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