是否可以根据所使用的操作系统来更改gradle的运行时依赖关系?
我在应用程序中使用SWT,该应用程序具有依赖于平台的jar。我只想为其运行的每个平台分发正确的SWT jar。就像是:
dependencies {
runtime fileTree(dir: 'swt', include: 'swt_win_32.jar') if windows.
runtime fileTree(dir: 'swt', include: 'swt_linux_x86.jar') if linux.
}
希望这个问题有意义。谢谢。
最佳答案
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)
}