Gradle构建来自多个文件夹的jar

时间:2017-08-25 12:45:15

标签: gradle

我有一个解压缩的罐子文件夹(如我删除了签名):

folder
    - unpackedJar1
    - unpackedJar2
    - unpackedJar3

现在我想再次将它们重新打包到罐子里,例如“unpackedJar1.jar”,“unpackedJar2.jar”等,并附带自定义清单。我该如何存档?我找不到有效的解决方案。

1 个答案:

答案 0 :(得分:0)

您可以为每个文件夹动态创建带有自定义清单的Jar任务,然后为它们分配一个聚合任务。例如:

task packAll{
    description = 'Pack all data in separated JARs'
}

//list of folders with unpacked data
def unpackedFolders = ['unpackedJar1', 'unpackedJar2', 'unpackedJar3']

//create new Jar task for each folder and make packAll depends on this one
unpackedFolders.each{ folderName ->
    def packTask = project.tasks.create(name: 'pack_' + folderName, type: Jar){
        archiveName = folderName + ".jar"
        from(project.files('folder/' + folderName))
        manifest{
            attributes( 
                'source': folderName
            )
        }
    }
    project.packAll.dependsOn packTask
}