Gradle Distribution Task Output Files Not at Root of ZIP

自古美人都是妖i 提交于 2019-12-09 08:13:49

问题


I created a simple Gradle build that exports the contents of ./src/main/groovy to a zip file. The zip file contains a folder with the exact same name as the zip file. I cannot figure out how to get the files into the root of the zip file using the distribution plugin.

i.e. gradlew clean distZip produces:

helloDistribution-1.0.zip -> helloDistribution-1.0 -> files

what I would like:

helloDistribution-1.0.zip -> files

My build.gradle file:

apply plugin: 'groovy'
apply plugin: 'distribution'

version = '1.0'

distributions {
    main {
        contents {
            from {
                'src/main/groovy'
            }
        }
    }
}

I have attempted to fix the problem by adding into { 'dir' } but to no avail.


回答1:


Using into '/' seems to do the trick:

contents {
    from {
        'src/main/groovy'
    }
    into '/'
}



回答2:


Unfortunately, penfold's answer did not work for me. Here is the solution I came up with:

task Package(type: Zip) {

    from {
        def rootScriptFiles = [] // collection of script files at the root of the src folder
        new File('src/main/groovy/').eachFile { if (it.name.endsWith('.groovy')) rootScriptFiles.add(it) }


        ['build/libs/',                 // build binaries
         'src/res/',                    // resources
         rootScriptFiles,               // groovy root source files
        ]
    }
    baseName = pluginName
}


来源:https://stackoverflow.com/questions/24496576/gradle-distribution-task-output-files-not-at-root-of-zip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!