Setting DerivedData path from xcodebuild command line tool

Hi

In order to support continuous integration, I've made a builder image with macOS and Xcode installed and I'd like to automate the process of building my workspace targets.

So I'm using the following command
/usr/bin/xcodebuild clean build -workspace ./myproj.xcworkspace -configuration Release -scheme myScheme

In my development machine I'm setting derived data location as relative to project directory from Xcode UI, so the build outputs are written under: <my project path>/DerivedData/myProj/Build/Products/Debug



However, in the build image I cannot set the derived data path since it also serves other projects.
Therefore, I'd like to find the appropriate flag to achieve similar behaviour from the xcodebuild command.

This means setting derived data location accordingly for all the targets which are being created in the build command. I've tried flags like CONFIGURATION_BUILD_DIR=./DerivedData or 
-derivedDataPath ./DerivedData but without success.

Any idea where am I go wrong ?

I'm also trying to figure this out. Did you ever find a solution, @chapo81?

I swear -derivedDataPath was working for a while, but then it stopped. After a git clean -dfx, xcodebuild started ignoring the -derivedDataPath setting, and writing to ~/Library/Xcode/Developer/DerivedData again.

Why can't xcodebuild just do the same thing as Xcode's build button?

This looks like a bug. You can see from the following output that xcodebuild is clearly ignoring the -derivedDataPath setting:

Command line invocation:
  /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project MyProj.xcodeproj -scheme "MyProj (iOS)" -destination "name=iPhone 12" -derivedDataPath=/Users/alpe77/myproj/MyProj/Build build

User defaults from command line:
  derivedDataPath = /Users/alpe77/myproj/MyProj/Build
  IDEPackageSupportUseBuiltinSCM = YES

note: Using new build system
note: Building targets in parallel
note: Planning build
note: Analyzing workspace
note: Using build description from disk
note: Build preparation complete
CodeSign /Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Products/Debug-iphonesimulator/MyProj.app (in target 'MyProj (iOS)' from project 'MyProj')
  cd /Users/alpe77/myproj/MyProj
  export CODESIGN_ALLOCATE\=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
   
  Signing Identity:   "-"
   
  /usr/bin/codesign --force --sign - --entitlements /Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Intermediates.noindex/MyProj.build/Debug-iphonesimulator/MyProj\ \(iOS\).build/MyProj.app.xcent --timestamp\=none /Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Products/Debug-iphonesimulator/MyProj.app
/Users/alpe77/Library/Developer/Xcode/DerivedData/MyProj-aozsidihjyumkvevtfoqflhumohn/Build/Products/Debug-iphonesimulator/MyProj.app: replacing existing signature

** BUILD SUCCEEDED ** [0.771 sec]

I was just hitting the same issue recently, found this, and noted a possible solution.

Using Xcode 15.4, when I used the -derivedDataPath argument, DONT specify the value with an = sign.

For example:

mkdir -p myDD
xcodebuild -scheme MyApp -derivedDataPath ./myDD test

worked as I hoped it might

Setting DerivedData path from xcodebuild command line tool
 
 
Q