Reputation: 309
What is the correct way for importing SWT the Gradle way in a Eclipse Java project?
The following solution on Stackoverflow does not work (it imports a tiny SWT library containing no classes, I can't make use of any SWT functionality):
Import SWT as a Gradle dependency
My application needs to use SWT UI classes and widgets (eg. Display, Shell, Composites and so on) and must absolutely be cross-platform.
Note that my application also uses LWJGL, which I can import successfully using the page below which does provide the full Gradle code to use (click build under Release then select Gradle):
LWJGL build.gradle import code
Thanks for your help.
Upvotes: 4
Views: 1299
Reputation: 12728
To complete the answer of @Ned Twigg, the full build.gradle
file should be like:
plugins {
id 'java'
id "com.diffplug.gradle.eclipse.mavencentral" version "3.17.3"
}
...
apply plugin: 'com.diffplug.gradle.eclipse.mavencentral'
eclipseMavenCentral {
release '4.7.0', {
compile 'org.eclipse.swt' // SWT for Windows in Gradle
useNativesForRunningPlatform()
}
}
Upvotes: 1
Reputation: 2224
Starting with Eclipse 4.6.2, SWT (and all of Eclipse) is published to maven central. If you're using Gradle, the goomph plugin has a mavencentral plugin that makes it pretty easy:
apply plugin: 'com.diffplug.gradle.eclipse.mavencentral'
eclipseMavenCentral {
release '4.7.0', {
compile 'org.eclipse.swt'
useNativesForRunningPlatform()
}
}
Upvotes: 1
Reputation: 27984
** Disclaimer ** I've never used SWT before
I'd put the SWT jars in a maven-like directory structure (note I've chosen random group/artifact/version here... please adjust appropriately)
myRepo/com/eclipse/swt/swt-core/4.1/swt-core-4.1-windows.jar
myRepo/com/eclipse/swt/swt-core/4.1/swt-core-4.1-linux.jar
myRepo/com/eclipse/swt/swt-utils/4.1/swt-utils-4.1-windows.jar
myRepo/com/eclipse/swt/swt-utils/4.1/swt-utils-4.1-linux.jar
You could do something like this in build.gradle
org.gradle.nativeplatform.platform.OperatingSystem os = org.gradle.internal.os.OperatingSystem.current()
def osDeps = []
if (os.windows) {
osDeps = ['com.eclipse.swt:swt-core:4.1:windows', 'com.eclipse.swt:swt-utils:4.1:windows']
} else if (os.linux) {
osDeps = ['com.eclipse.swt:swt-core:4.1:linux', 'com.eclipse.swt:swt-utils:4.1:linux']
} else ... {
}
apply plugin: 'java'
repositories {
maven {
url file('myRepo')
}
}
dependencies {
compile 'com.foo:common-stuff:1.0'
compile osDeps
}
Or if the SWT jars are available in a maven repository you should use that instead of a local folder.
Upvotes: 0
Reputation: 27984
I'm not entirely sure the differences between an eclipse plugin and an SWT application but you might be able to use the buildship build as a reference. The buildSrc utilities may be of use.
Upvotes: 0