[SOLVED] Gradle SWT dependies - error on compile

eclipse

(Vasiliy Altunin) #1

I use gradle with eclipse for my project, it seems all run just fine, all dependes inserted and project compile just fine. Now i wanna to create .exe file and i use https://github.com/TheBoegl/gradle-launch4j for it.

Here my gradle config:

buildscript {
  repositories {
jcenter()
  }
  dependencies {
classpath 'edu.sc.seis.gradle:launch4j:2.4.4'
  }
}


repositories {
  jcenter()
}


apply plugin: "java"
apply plugin: 'edu.sc.seis.launch4j'

launch4j {
  mainClassName = 'kanatrainer.MainWindow'
  icon = "${projectDir}/icons/myApp.ico"
}

task createMyExe(type: edu.sc.seis.launch4j.tasks.Launch4jExternalTask) {
launch4jCmd = 'launch4j-test'
outfile = 'kanatainer.exe'
}

// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'

// In this section you declare where to find the dependencies of your project

apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
ext {
appName = "kanatrainer"
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
maven { url "https://swt-repo.googlecode.com/svn/repo/"  }
}


sourceCompatibility = 1.8

sourceSets.main.java.srcDirs = [ "src/"]



apply from: 'gradle/swt.gradle'

defaultTasks 'build'


public String getPlatform(String platform) {
  switch (platform.replaceAll(' ', '').toLowerCase()) {
case ~/.*linux.*/:  return 'linux'
case ~/.*darwin.*/: return 'darwin'
case ~/.*osx.*/:    return 'darwin'
case ~/.*win.*/:    return 'windows'
default:            return null
  }
}

ext {
  swtVersion = '4.3'
  swtArtifactName = "org.eclipse.swt.${swtWindowingLibrary}.${swtPlatform}.${swtArch}"

  platform = getPlatform(System.properties['os.name'])
}

dependencies {
compile "org.eclipse.swt:${swtArtifactName}:${swtVersion}"
compile "org.eclipse.platform:org.eclipse.jface:3.12.2"
testCompile 'junit:junit:4.12'
}

and swt.gradle

public String getSWTWindowingLibrary(String platform) {
  switch (platform.replaceAll(' ', '').toLowerCase()) {
    case ~/.*linux.*/:  return 'gtk'
    case ~/.*darwin.*/: return 'cocoa'
    case ~/.*osx.*/:    return 'cocoa'
    case ~/.*win.*/:    return 'win32'
    default:            return null
  }
}

public String getSWTArch(String arch) {
  switch(arch) {
    case ~/.*64.*/: return 'x86_64'
    default:        return 'x86'
  }
}

public String getSWTPlatform(String platform) {
  switch(platform.replaceAll(' ', '').toLowerCase()) {
    case ~/.*linux.*/:  return 'linux'
    case ~/.*darwin.*/: return 'macosx'
    case ~/.*osx.*/:    return 'macosx'
    case ~/.*win.*/:    return 'win32'
    default:            return platform
  }
}

ext {
  swtWindowingLibrary = getSWTWindowingLibrary(System.properties['os.name'])
  swtArch = getSWTArch(System.properties['os.arch'])
  swtPlatform = getSWTPlatform(System.properties['os.name'])
}

Well i just get it from some one project and it works fine, maybe something is not necessary.

When i just refres gradle configuration from eclipse menu it runs without errors, but when i try run it default task i get error:

Working Directory: C:\java\kanatrainer
Gradle User Home: C:\Users\user\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 4.3
Java Home: C:\Program Files\Java\jre1.8.0_131
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: createMyExe

:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not find any matches for org.eclipse.platform:org.eclipse.swt.${osgi.platform}:[3.107.0,3.107.0] as no versions of org.eclipse.platform:org.eclipse.swt.${osgi.platform} are available.
  Searched in the following locations:
      https://jcenter.bintray.com/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/maven-metadata.xml
      https://jcenter.bintray.com/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/
      file:/C:/Users/user/.m2/repository/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/maven-metadata.xml
      file:/C:/Users/user/.m2/repository/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/
      https://repo1.maven.org/maven2/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/maven-metadata.xml
      https://repo1.maven.org/maven2/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/
      https://oss.sonatype.org/content/repositories/snapshots/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/maven-metadata.xml
      https://oss.sonatype.org/content/repositories/snapshots/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/
      https://oss.sonatype.org/content/repositories/releases/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/maven-metadata.xml
      https://oss.sonatype.org/content/repositories/releases/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/
      https://swt-repo.googlecode.com/svn/repo/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/maven-metadata.xml
      https://swt-repo.googlecode.com/svn/repo/org/eclipse/platform/org.eclipse.swt.${osgi.platform}/
  Required by:
      project : > org.eclipse.platform:org.eclipse.jface:3.12.2 > org.eclipse.platform:org.eclipse.swt:3.107.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
1 actionable task: 1 executed

What i possible doing wrong?


(Vasiliy Altunin) #2

Ok, i find solution.

Here new gradle config:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'edu.sc.seis.gradle:launch4j:2.4.4'
  }
}


repositories {
  jcenter()
}


apply plugin: "java"
compileJava.options.encoding = 'UTF-8'

apply plugin: 'edu.sc.seis.launch4j'

launch4j {
  mainClassName = 'kanatrainer.MainWindow'
  icon = "${projectDir}/icons/icon.ico"
}

task createMyExe(type: edu.sc.seis.launch4j.tasks.Launch4jExternalTask) {
    outfile = 'kanatainer.exe'
}

// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'

// In this section you declare where to find the dependencies of your project

apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
ext {
    appName = "kanatrainer"
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
	maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    maven { url "http://maven-eclipse.github.io/maven"  }
    
}


sourceCompatibility = 1.8

sourceSets.main.java.srcDirs = [ "src/"]



apply from: 'gradle/swt.gradle'

defaultTasks 'build'


public String getPlatform(String platform) {
  switch (platform.replaceAll(' ', '').toLowerCase()) {
    case ~/.*linux.*/:  return 'linux'
    case ~/.*darwin.*/: return 'darwin'
    case ~/.*osx.*/:    return 'darwin'
    case ~/.*win.*/:    return 'windows'
    default:            return null
  }
}

ext {
  swtVersion = '4.6.1'

  swtArtifactName = "org.eclipse.swt.${swtWindowingLibrary}.${swtPlatform}.${swtArch}"

  platform = getPlatform(System.properties['os.name'])
  
}

dependencies {
    compile "org.eclipse.swt:${swtArtifactName}:${swtVersion}"
	compile fileTree(dir: "libs", include: "*.jar")
    
    compile 'junit:junit:4.12'
    testCompile 'junit:junit:4.12'
}

and i create libs folder and put in it files:

org.eclipse.core.commands_3.9.100.v20180404-1234.jar
org.eclipse.jface_3.14.0.v20180423-0714.jar

so now gradle just insert them in project as external dependencies and all work just fine

to create exe i use

:createExe task