gradle命令行参数未传递给子任务

时间:2018-01-15 09:56:02

标签: gradle build.gradle command-line-arguments

无法在从命令行实际执行的任务调用的任务中使用命令行属性。请告诉我缺少什么?

build.gradle 摘录:

task createZip(type: Zip, dependsOn: 'copyContentToZip') {
    ext {
        buildNumber = project.hasProperty('buildNumber') ? project.property('buildNumber') : 'default'
        stagingDestPath= project.hasProperty('stagingDestPath') ? project.property('stagingDestPath') : 'C:/Sites/Project/releases/'
    }
    from tempContainerDir + projName 
    baseName projName +'-'+buildVersion+ '-'+ buildNumber
    destinationDir file(stagingDestPath)

}

task cleanBuildPublish(type: GradleBuild) {
    description 'Creates the clean build of oms.zip.'

    ext {
        buildNumber = project.hasProperty('buildNumber') ? project.property('buildNumber') : 'default'
        stagingDestPath= project.hasProperty('stagingDestPath') ? project.property('stagingDestPath') : 'C:/Sites/Project/releases/'
    }
     tasks = ['collectAllDependencies', 'createZip']
}

gradle.properties:

projName = test
buildVersion = 578
tempContainerDir = releases/tmp/

命令: gradlew -PbuildNumber = 2088 -PstagingDestPath = C:/ Sites / Project cleanBuildPublish

1 个答案:

答案 0 :(得分:2)

您可以将主构建的项目属性转发到嵌套构建:

task cleanBuildPublish(type: GradleBuild) {
    description 'Creates the clean build of oms.zip.'

    //forward projectProperties
    startParameter.projectProperties = project.gradle.startParameter.projectProperties

    ext {
        buildNumber = project.hasProperty('buildNumber') ? project.property('buildNumber') : 'default'
        stagingDestPath= project.hasProperty('stagingDestPath') ? project.property('stagingDestPath') : 'C:/Sites/Project/releases/'
    }
    tasks = ['collectAllDependencies', 'createZip']
}