# Processing Kotlin Syphon Gradle

**URL:** <https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927>\
**Category:** Libraries\
**Created:** [March 23, 2020, 9:28am UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927 "2020-03-23T09:28:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![membranobruno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/membranobruno/32/8508_2.png) [@membranobruno](https://discourse.processing.org/u/membranobruno)\
**Post date:** [March 23, 2020, 9:28am UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927/1 "2020-03-23T09:28:03Z")

</div>

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

```auto
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

```auto
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 = ''

}

```

---

<div class="post-metadata">

**Author:** ![robdin](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@robdin](https://discourse.processing.org/u/robdin)\
**Post date:** [March 23, 2020, 3:15pm UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927/2 "2020-03-23T15:15:45Z")

</div>

try to contact [https://openrndr.org](https://openrndr.org/)  
Hope that they can help u

---

<div class="post-metadata">

**Author:** ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)\
**Post date:** [March 23, 2020, 3:57pm UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927/3 "2020-03-23T15:57:02Z")

</div>

@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):

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

```

---

<div class="post-metadata">

**Author:** ![membranobruno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/membranobruno/32/8508_2.png) [@membranobruno](https://discourse.processing.org/u/membranobruno)\
**Post date:** [March 23, 2020, 5:26pm UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927/4 "2020-03-23T17:26:43Z")

</div>

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:

```auto
	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`

 ![screen](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8fbcc5879f32013c26a5e400d9301a4c0d301400.jpeg)

---

<div class="post-metadata">

**Author:** ![membranobruno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/membranobruno/32/8508_2.png) [@membranobruno](https://discourse.processing.org/u/membranobruno)\
**Post date:** [March 23, 2020, 5:50pm UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927/5 "2020-03-23T17:50:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![membranobruno](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/membranobruno/32/8508_2.png) [@membranobruno](https://discourse.processing.org/u/membranobruno)\
**Post date:** [March 23, 2020, 7:37pm UTC](https://discourse.processing.org/t/processing-kotlin-syphon-gradle/18927/6 "2020-03-23T19:37:58Z")

</div>

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… 😀
