Declaring platform specific dependencies in projects

Hi. I have another project (currently in Maven) which makes use of the SWT libraries.

The particular thing about the SWT libraries of course is that they are platform specific. So In short, how can I tell Gradle to use a certain version of the SWT jars when I’m working on the code base in, say, Windows or Linux?

One way to do this in Maven is:

<profiles>
 <profile>
  <id>windows_amd64</id>
  <activation>
   <os>
    <family>Windows</family>
    <arch>amd64</arch>
   </os>
  </activation>
  <dependencies>
   <dependency>
    <groupId>org.eclipse.swt</groupId>
    <artifactId>swt-win32-win32-x86_64</artifactId>
    <version>4.2.1</version>
   </dependency>
  </dependencies>
 </profile>
   <profile>
  <id>linux_x86_gtk2</id>
  <activation>
   <os>
    <family>linux</family>
    <arch>x86</arch>
   </os>
  </activation>
  <dependencies>
   <dependency>
    <groupId>org.eclipse.swt</groupId>
    <artifactId>swt-gtk-linux-x86</artifactId>
    <version>4.2.1</version>
   </dependency>
  </dependencies>
 </profile>
   <profile>
  <id>linux_amd64_gtk2</id>
  <activation>
   <os>
    <family>linux</family>
    <arch>amd64</arch>
   </os>
  </activation>
  <dependencies>
   <dependency>
    <groupId>org.eclipse.swt</groupId>
    <artifactId>swt-gtk-linux-x86_64</artifactId>
    <version>4.2.1</version>
   </dependency>
  </dependencies>
 </profile>
</profiles>

With this approach, the Maven project and Eclipse know what version of the SWT Jar they should use depending on the information reported by the Operating System.

Can I say the same in Gradle?

Thanks again for your time and help!

There’s no special support for this, but you can do something like:

def os = System.getProperty("os.name").toLowerCase()
if (os.contains("windows)") { ... }
else if (os.contains("linux") { ... }
else ...

Hi!

I have a project that has a dependency to an artifact that in this pom.xml file has dependencies on SWT like Jesús described above.

Gradle resolved the pom.xml file dependencies except for the activation of the profile that depends on the operating system.

Is there any way to solve this without using def os = System.getProperty (“os.name”). ToLowerCase () in my build.gradle file?