How to add multiple jars such that it will be picked up by an existing task in gradle?


(kant) #1

currently I have the following which generates the jar under project_name/build/libs

#Project A (build.gradle)
jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    from sourceSets.test.output
    baseName = 'SDK'
    exclude 'META-INF/.RSA', 'META-INF/.SF','META-INF/*.DSA'
}

build.dependsOn(linkToBin)

And this Jar will be collected by the following super class function

#MetaProject (build.gradle)
task linkToBin(dependsOn: jar) {
    doLast{
        File installDir = new File(rootProject.projectDir.getPath() + "/bin")
        installDir.mkdirs()
        configurations.testRuntime.allArtifacts.files.forEach {
            Path targetPath = Paths.get(installDir.getPath() + '/' + it.getName())
            if(new File(targetPath.toString()).exists())
               Files.delete(targetPath)
            Files.createSymbolicLink(targetPath, Paths.get(it.getPath()))
        }
    }
}

Driectory Structure as follows

MetaProject(directory with its own build.gradle)->Project A(sub directory with its own build.gradle)

I want to be able to create multiple jars within Project A and I would like all the jars to end up in MetaProject/bin just like above?