Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Gradle中使用SWT无法解析所有依赖项_Java_Eclipse_Maven_Gradle_Swt - Fatal编程技术网

Java 在Gradle中使用SWT无法解析所有依赖项

Java 在Gradle中使用SWT无法解析所有依赖项,java,eclipse,maven,gradle,swt,Java,Eclipse,Maven,Gradle,Swt,我试图在Gradle项目中使用最新的Eclipse SWT 3.114.0,但我得到了以下结果: > 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

我试图在Gradle项目中使用最新的Eclipse SWT 3.114.0,但我得到了以下结果:

   > 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
这是我的
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'
}

我在这里遗漏了什么?

首先,SWT现在正式发布在Maven Central上,所以您可能应该将
mavenCentral()
添加到您的repositories块中

其次,maven属性
osgi.platform
似乎不是由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")
            }
        }
    }
}