openbakery / gradle-xcodePlugin

gradle plugin for building Xcode Projects for iOS, watchOS, macOS or tvOS
Apache License 2.0
455 stars 127 forks source link

Question: Multiple tasks with different xcodebuild config #458

Closed thipokch closed 2 years ago

thipokch commented 2 years ago

Thanks for this awesome plug-in. I am trying to configure the plugin differently for each tasks, but it doesn't seems to work. The configurations in Kotlin DSL below seems to always use the last configuration. How would you go about configuring this?


    val buildDev by creating(XcodeBuildTask::class) {
        xcodebuild {
            scheme = "dev"
            target = "darwin"

              infoplist {
                  bundleIdentifier = "com.example.dev"
                  bundleDisplayName = "Example Dev"
              }
        }
    }

    val buildPre by creating(XcodeBuildTask::class) {
          xcodebuild {
              scheme = "pre"
              target = "darwin"

              infoplist {
                  bundleIdentifier = "com.example.pre"
                  bundleDisplayName = "Example Preview"
              }
          }
      }

    val buildPrd by creating(XcodeBuildTask::class) {
          xcodebuild {
              scheme = "prd"
              target = "darwin"

              infoplist {
                  bundleIdentifier = "com.example"
                  bundleDisplayName = "Example"
              }

        }
    }
renep commented 2 years ago

Gradle evaluates all the configuration an builds a task graph. The solution I use in my builds is to manipulate the taskGraph after it was build. Here is part of my build.gradle (in groovy) script that I have changed with your values:

gradle.taskGraph.whenReady { taskGraph ->
    if (taskGraph.hasTask(buildDev)) {
        xcodebuild {
            scheme = 'pre'
            target = 'darwin'
        }
        infoplist {
            bundleIdentifier = 'com.example.pre'
            bundleDisplayName = 'Example Preview'
        }
    }

    if (taskGraph.hasTask(buildPre)) {
        xcodebuild {
            scheme = 'pre
            target = 'darwin'
        }
        infoplist {
            bundleIdentifier = 'com.example'
            bundleDisplayName = 'example'
        }
    }
...
thipokch commented 2 years ago

@renep Thanks for the quick reply. :)