0
votes

In my case I have multiproject build with many subprojects and sub/subprojects.

Then I would like to be able to call this task from different subprojects to produce different jars set (basing on the project dependencies). In that way I would be able to create separate distribution for different subprojects.

I've come to the stage that I can list all of projects deps jars in an ugly way:

task showJars {
    doLast {
        if( configurations && configurations.getByName('compile') ) {
            configurations.compile.collect {
                if( !it.toString().contains('.gradle') )
                    println(it)
            }
        }
    }
}

I am working on a task to gather all project jars in one directory to create distribution for the app. Is there any clean way to achieve this ?

Thanks!

1
Could you please clarify the question? What's the desired output?Opal
I have multiproject build. Every subproject in this build outputs a jar as a result of gradle jar task. There are also dependencies between subprojects. I want to define a task which will create a projects jars and then copy them to one directory. The first part is to simply invoke gradle jar in the root or one of the subprojects, the second is to collect the project jars and copy them to one location.Piotr

1 Answers

0
votes

You might have to tweak the snippet below depending on your project and configuration, but this should give you the general idea:

task copyProjectDependencies << {
    file("build/project-dependencies").deleteDir()
    subprojects.findAll().each { project ->
        copy {
            from project.jar
            from project.configurations.runtime
            into "build/project-dependencies/jars"
        }
    }
}

You can also look at gradle's bundled application plugin:

apply plugin: 'application'

From the docs:

The Application plugin facilitates creating an executable JVM application. It makes it easy to start the application locally during development, and to packaging the application as a TAR and/or ZIP including operating system specific start scripts.

It will package it up as an archive with all dependencies.