Processing Kotlin Syphon Gradle

Hi. I’m experimenting with Kotlin and Processing. So, I have made the project with gradle and kotlin and the processing as the library. Also I use the shadowJar plugin to bundle the fatJar for distribution. Everything works well, but when I add syphon the shadowJar doesn’t include it in bundle. If I run gradle all works, but if I run the compiled jar file, the syphon is lost. I’m not the expert in gradle, maybe someone can help me. Thanks a lot.

Sketch

import processing.core.*
import processing.core.PConstants
import codeanticode.syphon.*


lateinit var syphon: SyphonServer
val speed  = 0.01f

class Sketch() : PApplet() {
    override fun settings() {
        size(800, 600, PConstants.P3D)
    }

    override fun setup() {
        syphon = SyphonServer(this, "Sketch")
    }

    override fun draw() {
      background(235f, 221f, 203f)
      lights()
      translate(width/2.toFloat(), height/2.toFloat())
      rotateX(frameCount.toFloat() * speed)
      rotateY(frameCount.toFloat() * speed)
      box(200f)
      syphon.sendScreen()
    }
}

fun main(args: Array<String>) {
    PApplet.main("Sketch")
}

Gradle

buildscript {
  ext.kotlin_version = '1.3.70'

  repositories {
    jcenter()
    mavenCentral()
  }

  dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
   
  }
}

apply plugin: "application"
apply plugin: "kotlin"
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'

mainClassName = 'MainKt'

repositories {
  jcenter()
  mavenCentral()
}

dependencies {
  compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  implementation files(
            '/Applications/Processing.app/Contents/Java/core/library/core.jar',
            '/Applications/Processing.app/Contents/Java/core/library/gluegen-rt-natives-macosx-universal.jar',
            '/Applications/Processing.app/Contents/Java/core/library/gluegen-rt.jar',
            '/Applications/Processing.app/Contents/Java/core/library/jogl-all-natives-macosx-universal.jar',
            '/Applications/Processing.app/Contents/Java/core/library/jogl-all.jar',
            '/Users/alex/Documents/Processing/libraries/Syphon/library/Syphon.jar',
            '/Users/alex/Documents/Processing/libraries/Syphon/library/jsyphon.jar',
    )
}

applicationDefaultJvmArgs = ['-Djava.library.path=/Users/alex/Documents/Processing/libraries/Syphon/library/']

shadowJar {
   baseName = 'app'
   classifier = ''
   archiveVersion = ''

}
1 Like

try to contact https://openrndr.org
Hope that they can help u

@membranobruno Please try to format your initial post with code tags. Otherwise it gets quite messy to look at it. And please specify exatcly, which jar is not bundled into your fatjar. Syphon contains of two different jars, one is the java-c wrapper and the other one is the Processing wrapper.

Please provide an error message or at least an information whats missing and what you expect.

Just a side note: Your fatjar won’t include the native syphon libraries which you added in the library path.

@robdin OpenRNDR is another creative framework, based on Kotlin and Gradle. But this seems more like a Jar / Gradle problem. I wouldn’t say the could not help, but it’s a bit random to ask them, regarding a Processing sketch. Stackoverflow would be the better option, because it is a more general problem.

In general, I bundle all my libraries (kotlin / java) with gradle using following task. Maybe this one works better for you (I never used shadow):

task fatJar(type: Jar) {
    archiveName = "my-fat.jar"
    dependsOn configurations.runtime
    from {
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    with jar
}

Hello cansik!!! The code has formatted. Actually, I inspired by your projects I found on github. I am from the python world, so kotlin looks much better for me and I desided to try this way )))

  • I run the project by gradle run. Result: Project starts and I see the sketch.
  • I run the project by gradle runShadow. Result: Project starts and I see the sketch. Also the app.jar is generated.
  • I run app.jar by java -jar app.jar. Result: Window appears with gray background and I got the error message:
	java.lang.UnsatisfiedLinkError: no JSyphon in java.library.path
	at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:408)
	at java.lang.Thread.run(Thread.java:748)

I think the problem is the jar file doesn’t include the applicationDefaultJvmArgs instruction. Why?
If I comment this instruction and just run the project (not the jar file), it will crash with the same error.

I have tried your recipe with task fatJar and I got the error no main manifest attribute, in my-fat.jar

I have some progress… if I run the app.jar from terminal this way:

java -Djava.library.path=/Users/alex/Documents/Processing/libraries/Syphon/library/ -jar app.jar

It works!!! So… the last question is how to add these instructions with java.library.path into jar bundle?

2 Likes

Found another solution. gradle clean build distZip
It creates the distribution script for mac/linux and .bat file for windows and it works well.

so much remains to be understood… :grinning:

2 Likes