Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
951 views
in Technique[技术] by (71.8m points)

how to copy all source jars using gradle

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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é


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...