How to copy all source jars using gradle

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

and I mean all the source banks that were loaded when I started gradle eclipse, when I saw that they loaded caching locations. We have a gradle eclipse eclipse call for Eclipsify for us in one project, so we can 100% just use gradle.

thanks dean

+5
source share
3 answers

, . (runtime + compile) java :

    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')
    }

, lenientConfiguration , , , . , .

, ,

+5

, .

, :

task copySourceJars( type: Copy ) {
  def sources = configurations.runtime.resolvedConfiguration.resolvedArtifacts.collect { artifact ->
    project.dependencies.create( [
      group: artifact.moduleVersion.id.group,
      name: artifact.moduleVersion.id.name,
      version: artifact.moduleVersion.id.version,
      classifier: 'sources'
    ] )
  }
  from configurations.detachedConfiguration( sources as Dependency[] )
    .resolvedConfiguration.lenientConfiguration.getFiles( Specs.SATISFIES_ALL )
  into file( 'some-directory/' )
}

javadocs jars, classifier javadoc.

+4

eskatos, DSL Kotlin:

tasks {
    "copySourceJars"(Copy::class) {
        val sources = configurations.runtime.resolvedConfiguration.resolvedArtifacts.map {
            with(it.moduleVersion.id) { 
                dependencies.create(group, name, version, classifier = "sources") 
            }
        }
        from(
            configurations.detachedConfiguration(*sources.toTypedArray())
                .resolvedConfiguration.lenientConfiguration.getFiles(Specs.SATISFIES_ALL)
        )
        into(File("some-directory"))
    }
}
0
source

All Articles