Change gradle runtime dependencies depending on operating system?

Is it possible to change the dependencies of gradle on runtime depending on which operating system it is included in?

I use SWT in my application, which has platform-dependent banks. I only want to distribute the right SWT-bank for each running platform. Sort of:

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 makes sense. Thanks.

+6
source share
3 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) } 
+6
source

Gradle does not have a public API for checking the OS, but you can use something like System.getProperty ("os.name") and act accordingly (for example, using a simple if statement).

+3
source

If you want to go with a more Gradle -ish way of doing this, you can use the Gradle OS plugin. https://bitbucket.org/tinhtruong/gradle-os-plugin

0
source

Source: https://habr.com/ru/post/905572/


All Articles