gradle build:使用变量作为工件名称

时间:2018-12-20 04:22:43

标签: gradle build artifactory

我正在创建一个gradle构建,该构建将构建几个子项目,然后将其发布到工件。 为了发布工件,我需要使用变量名称作为工件名称。这是必需的,因为工件的名称包含表示构建时间的时间戳。 从日志中,我可以看到实际发布是在完成子项目的构建之后发生的,但是看起来我用于工件名称的变量在被初始化之前被初始化,因此引发了错误。以下是发布部分:

publishing {
    publications {  
        // This publishes fine as it is picking the latest
        tests(MavenPublication) {
            artifactId 'tests'
            artifact ('tests/build/libs/tests.jar')
        }
        // I need to use a variable name for this
        // This looks for a .carb file in the sub project build directory
        carb(MavenPublication) {
            def carbFile = new File('carb/build/carbs').eachFileRecurse(FILES) {
                if(it.name.endsWith('.carb')) {
                    carbFileName = it
                }
            }
            println carbFileName
            artifactId 'carb'
            artifact carbFileName
        }
    }
}

对于发布目标'carb',我期望carbFileName在发布时会被填充,但是没有。我可以在发布开始之前看到println语句,因此它具有错误的值。有什么建议可以解决吗?

0 个答案:

没有答案
相关问题