Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build multiple architecture SWT application with Maven

I've set up a Maven project for a SWT application. This application runs on several platforms (OS X, Windows 64-bit, Windows 32-bit, Linux 64-bit and Linux 32-bit) and I've set it up so that the platform is detected when Maven is run and the packaged application goes to different destination directories. Here are the relevant parts from pom.xml to achieve this:

<profiles>
  <profile>
    <id>linux_x86_64</id>
    <activation>
      <os>
        <name>linux</name>
        <arch>amd64</arch>
      </os>
    </activation>
    <build>
      <directory>${project.basedir}/target/${project.version}/linux_x86_64</directory>
    </build>
  </profile>

  <profile>
    <id>win32_x86_64</id>
    <activation>
      <os>
        <name>linux</name>
        <arch>i386</arch>
      </os>
    </activation>
    <build>
      <directory>${project.basedir}/target/${project.version}/win32_x86_64</directory>
    </build>
    </profile>
  ...
</profiles>

And the dependency used for SWT is this:

<dependencies>
  <dependency>
    <groupId>org.eclipse</groupId>
    <artifactId>swt</artifactId>
    <version>3.7.2.v3740</version>
  </dependency>
...
</dependencies>

To make things clear, I have installed in my local repository the SWT dummy package (org.eclipse.swt_3.7.2.v3740f.jar) and all the platform-specific ones (org.eclipse.swt.gtk.linux.x86_64_3.7.2.v3740f, org.eclipse.swt.win32.x86_64_3.7.2.v3740f, etc.).

The way I pack dependencies is with a "lib" folder using the maven-dependency-plugin and Maven is smart enough to copy both the SWT dummy package and the platform-specific one of the machine where I'm packaging the application. So far so good...

The problem is that I would like to compile the application for the different platforms from a single machine. How would I achieve this?

I've tried setting up a property in each profile with the SWT jar needed for each platform, like this (example for Windows 64-bit):

<properties>
  <swt.artifactId>swt.win32.x86_64</swt.artifactId>
  <swt.version>3.7.2</swt.version>
</properties>

But taking this approach both the profile-specific SWT jar and the platform-specific one where I'm running Maven get copied into the "lib" directory, ending up with three jars:

  • swt-3.7.2.v3740.jar
  • swt.gtk.linux.x86_64-3.7.2.jar
  • swt.win32.x86_64-3.7.2.jar

Is there a way in which I could specify a profile ignoring the machine where I'm running it so that I don't need to manually remove its SWT jar?

Thanks in advance.

like image 634
Alf Avatar asked Apr 27 '12 17:04

Alf


1 Answers

Not sure how the depency-plugin handles it, but it should work if you have only one dependency like this one:

    <dependency>
        <groupId>${swt.groupId}</groupId>
        <artifactId>${swt.artifactId}</artifactId>
        <version>3.7.2</version>
        <scope>compile</scope>
    </dependency>

And then profiles like these:

<profile>
  <id>gtk_linux_x86_64</id>
  <activation>
    <os>
      <name>linux</name>
      <arch>x86_64</arch>
    </os>
  </activation>
  <properties>
    <swt.groupId>org.eclipse.swt.gtk.linux</swt.groupId>
    <swt.artifactId>x86_64</swt.artifactId>
  </properties>
</profile>

Now the needed version of SWT get's used automatically, but can be set to what you need (e.g. when building a release) as well using:

mvn -P gtk_linux_x86_64

Note: Change your groupId and artifactId as needed.

like image 96
hennr Avatar answered Sep 22 '22 18:09

hennr