Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify gradle's runtime dependencies according to operation system?

Is it possible to change gradle's runtime dependencies according to the what the operation system it is on?

I'm using the SWT in my application which has jars that are platform dependent. I want to only distribute the right SWT jar for each platform it is running. Something like:

dependencies {
    runtime fileTree(dir: 'swt', include: 'swt_win_32.jar') if windows.
    runtime fileTree(dir: 'swt', include: 'swt_linux_x86.jar') if linux.
}

Hope this question make sense. Thanks.

like image 521
Wudong Avatar asked Jan 09 '12 23:01

Wudong


1 Answers

String jarName;
switch(System.getProperty('os.name').toLowerCase().split()[0]) {
  case 'windows':
    jarName = 'swt_win_32.jar' 
    break
  case 'linux':
    jarName = 'swt_linux_x86.jar' 
    break
  default:
    throw new Exception('Unknown OS')
}

dependencies {
  runtime fileTree(dir: 'swt', include: jarName)
}
like image 109
Jerome Avatar answered Oct 07 '22 01:10

Jerome