Using SWT in Gradle could not resolve all dependencies
Asked Answered
S

1

5

I'm trying to use the latest Eclipse SWT 3.114.0 in my Gradle project, but I get the following:

   > Could not find org.eclipse.platform:org.eclipse.swt.${osgi.platform}:3.114.0.
     Searched in the following locations:
       - https://jcenter.bintray.com/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/3.114.0/org.eclipse.swt.${osgi.platform}-3.114.0.pom
       - https://repo.maven.apache.org/maven2/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/3.114.0/org.eclipse.swt.${osgi.platform}-3.114.0.pom
       - file:/C:/Users/voark/IdeaProjects/Eden-Dev/newlauncher/libs/org.eclipse.swt.${osgi.platform}-3.114.0.jar
       - file:/C:/Users/voark/IdeaProjects/Eden-Dev/newlauncher/libs/org.eclipse.swt.${osgi.platform}.jar
       - https://jcenter.bintray.com/org/eclipse/swt/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/3.114.0/org.eclipse.swt.${osgi.platform}-3.114.0.pom
     Required by:
         project : > org.eclipse.platform:org.eclipse.swt:3.114.0

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

This is my build.gradle:

import org.gradle.api.JavaVersion

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

mainClassName = 'com.legacypk.newlauncher.Main'

group 'com.legacypk'
version '1.0.0'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
    jcenter()
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile group: 'org.eclipse.platform', name: 'org.eclipse.swt.win32.win32.x86_64', version: '3.114.0'
    compile group: 'org.eclipse.platform', name: 'org.eclipse.swt.cocoa.macosx.x86_64', version: '3.114.0'
    compile group: 'org.eclipse.platform', name: 'org.eclipse.swt.gtk.linux.x86_64', version: '3.114.0'
    compile group: 'org.eclipse.platform', name: 'org.eclipse.swt.gtk.linux.ppc64le', version: '3.114.0'

    compile name: 'DJNativeSwing'
    compile name: 'DJNativeSwing-SWT'
}

What am I missing here?

Synthesize answered 28/5, 2020 at 4:58 Comment(0)
E
11

Firstly, SWT is being officially distributed on Maven Central now, so you should probably add mavenCentral() to your repositories block.

Secondly, the maven property osgi.platform doesn't seem to be handled by gradle. Instead, you'll have to do a bit of special dependency resolution to correctly grab the platform specific dependencies.

The following should work fine (lifted from https://github.com/LWJGLX/lwjgl3-swt/blob/master/build.gradle)

configurations.all {
    resolutionStrategy {
        dependencySubstitution {
            def os = System.getProperty("os.name").toLowerCase()
            if (os.contains("windows")) {
                substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') with module("org.eclipse.platform:org.eclipse.swt.win32.win32.x86_64:3.114.0")
            }
            else if (os.contains("linux")) {
                substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') with module("org.eclipse.platform:org.eclipse.swt.gtk.linux.x86_64:3.114.0")
            }
            else if (os.contains("mac")) {
                substitute module('org.eclipse.platform:org.eclipse.swt.${osgi.platform}') with module("org.eclipse.platform:org.eclipse.swt.cocoa.macosx.x86_64:3.114.0")
            }
        }
    }
}
Effectually answered 28/5, 2020 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.