uklance / gradle-dependency-export

Export maven dependencies from a gradle project to the file system
27 stars 14 forks source link

Idea: include source packages #6

Closed stefanleh closed 5 years ago

stefanleh commented 5 years ago

Id like to see sources packages for the resolved dependencies included via configuration switch. This would help if the file based repository the plugin creates get directly used by buildship. Buildship fetches the source packages for the defined dependencies by default but for this they need to be in the repository.

uklance commented 5 years ago

This can be done via an ArtifactResolutionQuery

See https://stackoverflow.com/questions/39975780/how-can-i-use-gradle-to-download-dependencies-and-their-source-files-and-place-t/39981143#39981143

apply plugin: 'java'

repositories { ... }

dependencies {
    compile 'foo:bar:1.0'
    runtime 'foo:baz:1.0'
}

task download {
    inputs.files configurations.runtime
    outputs.dir "${buildDir}/download"
    doLast {
        def componentIds =
configurations.runtime.incoming.resolutionResult.allDependencies.collect {
it.selected.id }
        ArtifactResolutionResult result =
dependencies.createArtifactResolutionQuery()
            .forComponents(componentIds)
            .withArtifacts(JvmLibrary, SourcesArtifact)
            .execute()
        def sourceArtifacts = []
        result.resolvedComponents.each { ComponentArtifactsResult component
->
            Set<ArtifactResult> sources =
component.getArtifacts(SourcesArtifact)
            println "Found ${sources.size()} sources for ${component.id}"
            sources.each { ArtifactResult ar ->
                if (ar instanceof ResolvedArtifactResult) {
                    sourceArtifacts << ar.file
                }
            }
        }

        copy {
            from configurations.runtime
            from sourceArtifacts
            into "${buildDir}/download"
        }
    }
}
stefanleh commented 5 years ago

Great news! I will build the feature in the coming days based on this information.

uklance commented 5 years ago

Great, to get sources and javadoc you'll need to tweak

.withArtifacts(JvmLibrary, SourcesArtifact)

To

.withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact)

On Mon, 25 Feb 2019, 8:32 am Stefan, notifications@github.com wrote:

Great news! I will build the feature in the coming days based on this information.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/uklance/gradle-dependency-export/issues/6#issuecomment-466916946, or mute the thread https://github.com/notifications/unsubscribe-auth/ABW1JC1PigZ4b6cKVNSG6HqkAF3-EIEDks5vQ5-vgaJpZM4bPR1b .

stefanleh commented 5 years ago

Sounds good. Will introduce switched for 'withSources' and 'withJavaDoc' then.

uklance commented 5 years ago

Perhaps two flags on the task

boolean exportSources boolean exportJavadoc

On Mon, 25 Feb 2019, 9:53 am Stefan, notifications@github.com wrote:

Sounds good. Will introduce switched for 'withSources' and 'withJavaDoc' then.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/uklance/gradle-dependency-export/issues/6#issuecomment-466947320, or mute the thread https://github.com/notifications/unsubscribe-auth/ABW1JNf-MsJs9lnAb9ASvpq7_meJrT5Lks5vQ7KGgaJpZM4bPR1b .